SQL SERVER – 2008 – Get Current System Date Time

How to get current system date time in SQL Server?

First thing which comes to many users is using following script.


SELECT GETDATE() AS CurrentDateTime

Above method is not the only method to retrieve the current system date time for SQL Server. SQL Server 2008 has many different function which provides current system date time in different format and little difference in details.


SELECT 'SYSDATETIME' AS FunctionName, SYSDATETIME() AS DateTimeFormat
UNION ALL
SELECT 'SYSDATETIMEOFFSET', SYSDATETIMEOFFSET()
UNION ALL
SELECT 'SYSUTCDATETIME', SYSUTCDATETIME()
UNION ALL
SELECT 'CURRENT_TIMESTAMP', CURRENT_TIMESTAMP
UNION ALL
SELECT 'GETDATE', GETDATE()
UNION ALL
SELECT 'GETUTCDATE', GETUTCDATE()

In SQL Server 2008, use any of the above function depending on your need.

Here is what each one gives you, so you can pick the right one:

  • GETDATE() and CURRENT_TIMESTAMP return the same local server time as DATETIME, rounded to about 3 milliseconds. CURRENT_TIMESTAMP is simply the ANSI standard name.
  • GETUTCDATE() returns the same DATETIME value, but in UTC.
  • SYSDATETIME() returns local time as DATETIME2(7), with precision down to 100 nanoseconds.
  • SYSUTCDATETIME() is the DATETIME2(7) version in UTC.
  • SYSDATETIMEOFFSET() returns DATETIMEOFFSET(7), which also carries the server’s time zone offset.

My rule of thumb: GETDATE() is fine for most everyday work. Use SYSDATETIME() when you need finer precision, and the UTC versions when your servers or users sit in different time zones.

SQL Server query window with date time query.

Quick Video on the same subject

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

SQL DateTime, SQL Function, SQL Scripts, SQL Server
Previous Post
SQL SERVER – 2008 – Find Current System Date Time and Time Offset
Next Post
SQL SERVER – 2005 – Get Field Name and Type of Database Table

Related Posts

39 Comments. Leave new

  • i want a qurey that minus system date and my date in data base like i want to use it on searching select * from emp where systemdate-mydate>=120days
    can you plz tell me the qurey for that i am confused how to minus sysdate and mydate
    mydate is my column name kindly mail me the solution

    Reply
  • Hi,i made databse is in vusualstudio 2010 i want to get date automatically from my system without entering date manually in text box.i need to get date automatically from system and store it in databse with other enteries……………….
    please tell me how to do it???????

    Reply
  • Thanks for this post. I didn’t get a chance yet to work on SQL Server 2008 or above. Should try it in future.

    Reply
  • SELECT ‘FUNCTION’,CAST( {fn NOW()} AS DATETIME)
    SELECT ‘FUNCTION’,CAST( GETDATE() AS DATETIME)

    Reply
  • How to get system’s date format using sql statement?

    Reply
  • hello sir this is chandru i have developed chit fund software i need to make autoupdated when purticular date changed to next date kindly help me sir

    Reply
  • i am not understand

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.