SQL Server 5 Ways to Get Now and their Differences— current_timestamp, getdate, getdateutc, sysdatetime, sysutcdatetime

tanut aran
1 min readMay 1, 2024

Try the Query on DBeaver


SELECT
CURRENT_TIMESTAMP,
SYSDATETIME(),
SYSUTCDATETIME(),
GETDATE(),
GETUTCDATE()

Cannot even notice the different between each one.

Difference — Data type

  1. GETDATE() return DATETIME type
  2. SYSDATETIME() return DATETIME2 type

Difference — Timezone

  1. GETDATE() and SYSDATETIME() return date time with LOCAL time zone
  2. GETUTCDATE() and SYSUTCDATETIME()return date time with UTC time zone

Difference — SQL Standard

The CURRENT_TIMESTAMP is included because of the standard SQL use it

CURRENT_TIMESTAMP is GETDATE()

Both on timezone and data type.

Why in the example return the same value?

Because I do not set the timezone of the database.

See Microsoft doc / Google it to set it.

For example, in Linux you can set it by TZ or /etc/ then reload the service. On AWS RDS, you can do it on ‘Additional configuration’ screen.

You can also check it by

SELECT SYSDATETIMEOFFSET()

-- 2024-05-01 10:21:07.744 +0000
-- if it is 0000 it does not have any offset

--

--