Open In App
Related Articles

DAY() Function in SQL Server

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

DAY() function :
This function in SQL Server is used to return the day of the month i.e, from 1st to 31st for date stated.

Features :

  • This function is used to find the day of the month for a date specified.
  • This function comes under Date Functions.
  • This function accepts only one parameter i.e, date.
  • This function can also include time with the stated date.

Syntax :

DAY(date)

Parameter :
This method accepts only one parameter as given below as follows.

  • date –Specified date from which the day of the month is to be returned.

Returns :
It returns the day of the month i.e, from 1st to 31st for a date specified.

Example-1 :
Using DAY() function and getting the day of the month from the date specified.

SELECT DAY('2020/01/02');

Output :

2

Example-2 :
Using DAY() function with a variable and getting the day of the month from the date specified.

DECLARE @date VARCHAR(50);
SET @date = '2020/01/05';
SELECT DAY(@date);

Output :

5

Example-3 :
Using DAY() function with date as parameter which includes time as well.

SELECT DAY('2018/11/22 07:44');

Output :

22

Example-4 :
Using DAY() function with a variable and a date as parameter which includes time as well.

DECLARE @date VARCHAR(50);
SET @date = '2020/11/30 23:59';
SELECT DAY(@date);

Output :

30

Application :
This function is used to find the day of the month from the date specified.

Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our Complete Interview Preparation course.

Last Updated : 18 Jan, 2021
Like Article
Save Article
Previous
Next
Similar Reads