SQL Day function is one of the Date and Time Function, which will return an integer that represents the day of a specified Date. The basic syntax of the SQL Server DAY Function is as follows:
date: It can be an expression that returns the date, or you can use the date and time directly.
For this Day function example, We are going to use the below-shown data
SQL DAY Function Example
In this example, we will show you the possible ways to use the Day function
-- Example for SQL DAY Function -- Testing Day Function with Random Date SELECT DAY('12-19-05') AS [Day Example 1] -- Testing Day Function with Random Date and Time SELECT DAY('2015-05-14 12:29:44.513') AS [Day Example 2] -- Testing Day Function with Todays Date SELECT DAY(GETDATE()) AS [Todays Date]
-- Example for SQL DAY Function USE [SQL Tutorial] GO SELECT [EmpID] ,[FirstName] + ' '+ [LastName] AS [Full Name] ,[Occupation] ,[YearlyIncome] ,[HireDate] ,DAY([HireDate]) AS [Today] ,DATEPART (day, [HireDate]) AS [TodayFromDatePart] FROM [Employee]
From the below screenshot, you can observe that the DATEPART function, and Day function are returning the same result.