Groups | Blog | Home
all groups > sql server clients > april 2004 >

sql server clients : DateTime in UTC format



Keshav
4/2/2004 10:20:43 AM
Hi All,

I have the following table structure=20

CREATE TABLE [test]=20
([dd] [datetime] NULL)

I have a stored procedure to insert values to the above table. The SP is =
invoked from a .NET application written in C#.=20
I have to store date time in UTC format.I am able to convert local date =
time to UTC format in C# by following code :

DateTime _datetime =3D DateTime.Now;
string _formattedDateTime =3D _datetime.ToUniversalTime().ToString("s", =
DateTimeFormatInfo.InvariantInfo) + "Z";

Eg. "2004-04-01T04:00:17Z". [the symbol Z means it is in UTC].

When I pass this value to=20
The SP is as follows :

CREATE PROCEDURE SP_Insert
@dd Varchar(30)
AS
insert into test1 (dd) values(convert(datetime,@dd,126))=20
GO

when i execute the sp

exec sp_insert '2004-04-01T04:00:17Z'=20

I get error as "Syntax error converting datetime from character string."

I thought of storing the datetime as string in that case how to convert =
the string to datetime (in UTC format)?

Any suggestions would be greatly appreciated...=20

Thanks in Advance
Abhinav Kumar
4/5/2004 12:34:41 AM
Use datetime as the input parameter or split the date and
time into two different columns

Abhinav Kumar
akumar@itmag.com.au

[quoted text, click to view]
table. The SP is invoked from a .NET application written
in C#.
[quoted text, click to view]
convert local date time to UTC format in C# by following
code :
[quoted text, click to view]
case how to convert the string to datetime (in UTC
format)?
[quoted text, click to view]
AddThis Social Bookmark Button