Member-only story

Nidhi Gupta
2 min readApr 22, 2021

--

DATE_TIME functions in SQL server

— Function to get the system’s date and time

SELECT SYSDATETIME(); — function to get the system’s current date and time with decimal precision of 7 digits

2021–04–22 10:45:03.4318758

select CURRENT_TIMESTAMP;

select GETDATE(); — function to get the system’s current date and time with decimal precision of 3 digits

SELECT SYSDATETIMEOFFSET(); — function to get the system’s current date and time + offset

2021–04–22 10:46:11.1008493 +05:30

SELECT SYSUTCDATETIME(); — function to get the system’s current date and time in UTC format with decimal precision of 7 digits

2021–04–22 05:17:27.1006020

SELECT GETUTCDATE(); — function to get the system’s current date and time in UTC format with decimal precision of 3 digits

2021–04–22 05:24:12.270

— Function Datename and Datepart

— DATENAME — returns a string corresponding to the date specified

— DATEPART — Used to extract part of a string

SELECT DATENAME(YEAR, GETDATE()) AS ‘Year’; or

SELECT DATEPART(YEAR, GETDATE()) AS ‘Year’;

2021

SELECT DATENAME(QUARTER, GETDATE()) AS ‘QUARTER’; or

SELECT DATEPART(QUARTER, GETDATE()) AS ‘QUARTER’;

--

--

Nidhi Gupta
Nidhi Gupta

Written by Nidhi Gupta

Azure Data Engineer 👨‍💻.Heading towards cloud technologies expertise✌️.

No responses yet