Check current date and Time in Microsoft SQL Server

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.