How get current date and time from SQL Server ?

In this post I describe T-SQL functions get current date and time.

This date and time are getting from computer where instance of SQL Server is running.

    Transact SQL delivers two kind of functions:

  • higer-precision system date and time,
  • lower-precision system date and time.
    Higer-precision system date and time functions:

  • SYSDATETIME() – return datetime2(7)
  • SYSDATETIMEOFFSET() – return datetimeoffset(7), add time zone
  • SYSUTCDATETIME() – return datetime2(7) as UTC(Coordinated Universal Time) time
SELECT
      SYSDATETIME() AS 'SYSDATETIME' ,
      SYSDATETIMEOFFSET() AS 'SYSDATETIMEOFFSET',
      SYSUTCDATETIME() AS 'SYSUTCDATETIME' ;

S1

    Lower-precision system date and time functions:

  • CURRENT_TIMESTAMP – return datetime
  • GETDATE() – return datetime
  • GETUTCDATE() – return datetime as UTC(Coordinated Universal Time) time<
SELECT
      CURRENT_TIMESTAMP AS 'CURRENT_TIMESTAMP' ,
      GETDATE() AS 'GETDATE',
      GETUTCDATE() AS 'GETUTCDATE' ;

S2In Poland time zone is +2 hours, so in UTC  the time is 2 hours previous. Higer-precision system date and time functions show 7 signs in fractional precision of second, and lower-precision system date and time functions show only 3 signs in fractional precision of second.