MSSQL: Getdate()

Kumar, Thrainder (MIND) 176 Reputation points
2021-05-26T10:01:44.08+00:00

Hi,

I have been using MSSQL for a while and observed that the Getdate() always returns manipulated time.
Like the last digit of the time is always 0,3 or 7

99843-image.png

99809-image.png

99861-image.png

I want to know how its works.

99853-image.png

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 47,436 Reputation points
    2021-05-26T10:18:21.377+00:00

    Getdate() always returns manipulated time. Like the last digit of the time is always 0,3 or 7

    It's not manipulated"; GetDate() returns a vlaue of data type "datetime" and datetime do have a Accuracy of 3 1/3 milliseconds and thats well documented at datetime (Transact-SQL) => Accuracy

    This query

    select convert(datetime, '20210525 23:59:59.999')  
    

    returns 2021-05-26 00:00:00.000

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2021-05-26T12:46:23.057+00:00

    If you need higher precision you need to use datetime2 and sysdatetime.

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

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.