Datetime

Last Post 23 Apr 2007 08:17 PM by SQLUSA. 4 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
brewer234
New Member
New Member

--
23 Apr 2007 06:06 AM
Hi Everyone,

This is a genaral query about SQL DateTime and System.DateTime.

Is there any guidlines on when to use which?

I have a SP that accepts a param of type DateTime if I try to pass System.DateTIme.Now to it I get a Input string was in incorrect format error.

So I am casting System.DateTime to System.Data.SqlClients.DateTime which works.

Maybe I am being too fussy, but just wondered what anyones thoughts are on this?

Thanks in advance.
SQLUSA
New Member
New Member

--
23 Apr 2007 08:17 PM
You can get the server datetime by the getdate() function in SQL Sever 2005.

There is no need to get system time from the client in a sproc, unless working in multiple timezones environment and needed to capture the local time.

Kalman Toth, Database Architect
SQL Server 2005 Training - http://www.sqlusa.com/order2005
brewer234
New Member
New Member

--
23 Apr 2007 09:41 PM
Thanks for the reply Kalman.

I also want to a specific date to the DB using the SP so I need to pass different dates to it.
SQLUSA
New Member
New Member

--
24 Apr 2007 12:00 AM
You can pass dates in the following formats:

datetime
smalldatetime
char(10) - like '2007/04/24'

Passing local system time may lead to inaccuries in the database if the client clock is not synched with the server. In such a case, you can just pass the timezone and the time is picked up at the server.
brewer234
New Member
New Member

--
24 Apr 2007 04:20 AM
Thanks for your replies guys.

I think it might have been more of a .Net architech question really.

I guess the upshot is that if the SP accepts a param of DateTime then I should use the SQL DateTime variable in my .Net code not the .Net built in date type.
You are not authorized to post a reply.

Acceptable Use Policy