SQL Server 2005/2008 has a GETUTCDATE() function that retreives the local machine's date and time without the time zone offset, representing the current UTC time (Coordinated Universal Time) or GMT (Greenwich Mean Time).
If you need a more fractional seconds precision, use the SYSUTCDATETIME instead of GETUTCDATE()
Let's see the results when running some common date and time functions in SQL Server:
SELECT GETDATE() - 2009-03-28 13:08:37.553
SELECT SYSDATETIME() - 2009-03-28 13:08:37.5570000
SELECT GETUTCDATE() - 2009-03-28 07:38:37.557
SELECT SYSUTCDATETIME() - 2009-03-28 07:38:37.5570000
SELECT SYSDATETIMEOFFSET() - 2009-03-28 13:08:37.5570000 +05:30
As you can observe, the SYSDATETIME and SYSUTCDATETIME are used to display time with fractional second precision. The SYSDATETIMEOFFSET displays the time zone offset.
To find a difference between the Local time and UTC time use this query:
SELECT DATEDIFF(MINUTE,GetDate(),GetUTCDate());
Note: You may also want to checkout the SYSUTCDATETIME SWITCHOFFSET and TODATETIMEOFFSET functions
About The Author
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of
DotNetCurry,
DNC Magazine for Developers,
SQLServerCurry and
DevCurry. He has also authored a couple of books
51 Recipes using jQuery with ASP.NET Controls and a new one recently at
The Absolutely Awesome jQuery CookBook.
Suprotim has received the prestigous Microsoft MVP award for nine times in a row now. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that represents premium web sites and digital publications comprising of Professional web, windows, mobile and cloud developers, technical managers, and architects.
Get in touch with him on Twitter @suprotimagarwal, LinkedIn or befriend him on Facebook
1 comment:
no comments please
Post a Comment