Check current date and time in MSSQL Database
Check current date function:
SELECT
GETDATE() as 'GETDATE()'
,CURRENT_TIMESTAMP as 'CURRENT_TIMESTAMP'
,SYSDATETIME() as 'SYSDATETIME()';
Output:
GETDATE() CURRENT_TIMESTAMP SYSDATETIME()
2022-01-08 21:49:21.767 2022-01-08 21:49:21.767 2022-01-08 21:49:21.7673530
Check the UTC and Time zone Offset
SELECT
SYSDATETIMEOFFSET() as 'SYSDATETIMEOFFSET()'
,GETUTCDATE() as 'GETUTCDATE()'
Output:
SYSDATETIMEOFFSET() GETUTCDATE()
2022-01-08 21:51:07.9431907 +05:30 2022-01-08 16:21:07.940
Check small date and time in MSSQL:
select CAST(getdate() as smalldatetime) as 'Smalldatetime'
Output:
Smalldatetime
2022-01-08 21:53:00
Get the only date in MSSQL:
select cast(getdate() as date) as 'DATE'
Output:
DATE
2022-01-08
Get the only time in MSSQL:
select cast(getdate() as time) as 'TIME'
Output:
TIME
21:55:10.3966667