Announcement

Collapse
No announcement yet.

How can I get local time of a SQL server?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I get local time of a SQL server?

    How can I get local time of a SQL server and store it in a variable?

  • #2
    Sven,

    You can get the local time of the SQL Server by using the getdate() system function.

    SELECT getdate()
    If you want to get UTC time use the getutcdate() system function.

    SELECT getutcdate()
    Hope it works...

    Comment


    • #3
      Hi Sven,

      You can also do this:
      Code:
      SELECT CONVERT(datetime,
                     SWITCHOFFSET(CONVERT(datetimeoffset,
                                          MyTable.UtcColumn),
                                  DATENAME(TzOffset, SYSDATETIMEOFFSET())))
             AS ColumnInLocalTime
      FROM MyTable

      Comment

      Working...
      X