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]
In this example, we are going to extract the Date from Employee table using the DATEPART Function, and Day function.
-- 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.
Remember, before 2012, people used the DATEPART function to extract the day, but in SQL Server 2012, Microsoft introduced the day function.