question

KumarThrainderMIND-0302 avatar image
0 Votes"
KumarThrainderMIND-0302 asked TomPhillips-1744 answered

MSSQL: Getdate()

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


sql-server-generalsql-server-transact-sql
image.png (1.4 KiB)
image.png (1.5 KiB)
image.png (1.3 KiB)
image.png (39.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

OlafHelper-2800 avatar image
1 Vote"
OlafHelper-2800 answered OlafHelper-2800 edited

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TomPhillips-1744 avatar image
1 Vote"
TomPhillips-1744 answered

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

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.