You are currently viewing How To Get Day From Date in SQL Server

How To Get Day From Date in SQL Server

DAY() function is used to get day from the date provided in the DAY() function. It gives the single day result in positive integer between first day of the month to last day of the month.

General Syntax is as follows:

SELECT DAY(DateParameter)

Get day from GETDATE() Function

We can get day from GETDATE() function which gives the day in integer from the current date.

SELECT DAY(GETDATE()) AS DayFromGetDate

Output

Day from getdate

Get day from date provided as string in single quotes

We can get day from date provided as string in single quotes which gives the day in integer.

SELECT DAY('2022/01/31') AS DayFromDate

Output

Day from date in string

Get day from table Column

We can get day from table having DATETIME data type. To get the day from the table columns, first we create a table and insert some rows and then we will get the day from that particular column.

USE HR
GO
CREATE TABLE tblEmployee
(
    EmpID INT PRIMARY KEY NOT NULL,
    EmpName VARCHAR(20),
    EmpGender VARCHAR(10),
    EmpAge INT,
    EmpSalary INT,
    EmpJoiningDate DATETIME
)
GO

Let’s insert some records into tblEmployee table.

USE HR
GO
INSERT INTO tblEmployee
VALUES
    (1,'Simon','Male',25,25000,'2015-01-01 22:04:49.400'),
    (2,'Dave','Male',29,15000,'2016-03-25 20:04:55.400'),
    (3,'Sara','Female',35,20000,'2017-05-01 18:04:35.400'),
    (4,'Julia','Female',36,35000,'2018-01-10 15:03:45.400'),
    (5,'Sam','Male',32,35000,'2020-03-20 10:02:25.400')
GO

Below is the result of records of table tblEmployee.

Day function table data

Now, below is the query to get day from the EmpJoiningDate column of the table tblEmployee.

USE HR
GO
SELECT
    EmpName,
    EmpGender,
    EmpSalary,
    DAY(EmpJoiningDate) AS JoiningDay
FROM tblEmployee
GO

Output

Day function practical

Recommended Readings

Buy Best Stationery Products in Pakistan

Piano Ballpoint Pen

Piano Ballpoint Pen

ORO Trimetal Pencil

ORO Trimetal

Dollar Clipper Pen

UHU 10×7 ml Pack of 10 PCs

UHU 10×7 ml Pack of 10 PCs

Glue Stick 8g Pack Of 12 PCs

Glue Stick 8g

Color Pencils Box of 12 PCs

Deer Multi Color Pencils