Date and Time in SQL Server

The SQL date and time functions are used to work with date and time data types.

1. Get current date and time in SQL Server

Syntax:
I) SELECT GETDATE()

II)  SELECT SYSDATETIME

The GETDATE() function gives the current date and time and the SYSDATETIME function gives the more precise value.

2. To get day, month, and year in SQL Server

To get day, month and year of the date user can use DAY, MONTH and YEAR function by passing the current date.

Syntax

SELECT
DAY(GETDATE()) AS Day,
MONTH(GETDATE()) AS Month,
YEAR(GETDATE()) AS Year


3. To get week day name, week day, and month name in SQL Server

Syntax

SELECT
DATENAME(WEEKDAY, GETDATE()) AS DayName,
DATEPART(WEEKDAY, GETDATE()) AS DayOfTheWeek,
DATENAME(MONTH, GETDATE()) As MonthName