SQL Server 5 Ways to Get Now and their Differences— current_timestamp, getdate, getdateutc, sysdatetime, sysutcdatetime
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
GETDATE()
returnDATETIME
typeSYSDATETIME()
returnDATETIME2
type
Difference — Timezone
GETDATE()
andSYSDATETIME()
return date time with LOCAL time zoneGETUTCDATE()
andSYSUTCDATETIME()
return date time with UTC time zone
Difference — SQL Standard
The CURRENT_TIMESTAMP
is included because of the standard SQL use it
CURRENT_TIMESTAMP
isGETDATE()
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