Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to get datetime with like following format

2011-05-23 19:43:32.7577956 +05:00

using SQL Server 2005 (T-SQL)

Thanks
Posted
Updated 23-May-11 6:04am
v2
Comments
mhwasim 24-May-11 8:37am    
I have created a CLR to get this done on SQL 2005....It works for me...
Thanks for all of you to helpme on this....

Not very clear on what you are looking for, but this should help:
How to format datetime & date in Sql Server[^]
datetime (Transact-SQL)[^]
 
Share this answer
 
Comments
mhwasim 23-May-11 11:55am    
It is clear that I want the date time value like the following format
2011-05-23 19:43:32.7577956 +05:00
in SQl 2008 we can get this by SELECT SYSDATETIMEOFFSET()

and in SQL 2005 the workaround is
DECLARE @OffsetValue int;
SET @OffsetValue = (SELECT DATEDIFF(hh, GETUTCDATE(), GETDATE()));
SELECT @OffSetValue AS [TimeOffset];

I want to know if there is a function which will give me this value directly without any calculations...
Sandeep Mewara 23-May-11 12:50pm    
1. If it is '+05:00', how is it GMT? You trying for any specific timezone?
2. What your effort was, should had been the part of the question earlier instead of a comment now.
mhwasim 23-May-11 14:04pm    
My appologies......I was busy on some other work and didnt notice about it....Thanks for the correction...
SELECT SYSDATETIMEOFFSET()


Google reveals all...
 
Share this answer
 
v2
Comments
mhwasim 23-May-11 12:02pm    
its for SQL 2K8...will not work in SQL2K5..check my comments in solution 1...I already mention it
I have created a CLR to get this done on SQL 2005....It works for me...
Thanks for all of you to helpme on this....

.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900