Search code examples
datetimegetdatesql-server-2019

Getdate() in sql-server 2019 giving wrong date


I am simply running the below command :

select getdate()

and I am getting below same result for last 30 min:

2020-07-21 15:45:14

Which is incorrect. Also it's not changing with every second.

Not sure if I am missing something.


Solution

  • You are probably querying a replicate, the getdate() returns the latest database system timestamp, not the system time of the local machine.

    SELECT CONVERT (time, SYSDATETIME())
        ,CONVERT (time, SYSDATETIMEOFFSET())
        ,CONVERT (time, SYSUTCDATETIME())
        ,CONVERT (time, CURRENT_TIMESTAMP)
        ,CONVERT (time, GETDATE())
        ,CONVERT (time, GETUTCDATE());
    

    see https://learn.microsoft.com/en-us/sql/t-sql/functions/getdate-transact-sql?view=sql-server-ver15

    If you need to know the local computer time, then use SYSDATETIME instead