How to Get the Day from a Date in T-SQL Database: MS SQL Server Operators: DAY() Table of Contents Problem Example Solution Discussion Problem You’d like to get the number of day from a date field in a SQL Server database. For example, from the date of February 27, 2023, you'd like to get the number 27. Example Our database has a table named MedicalVisit with data in the columns Id, FirstName, LastName, and VisitDate. IdFirstNameLastNameVisitDate 1JaneMiller2019-11-17 2AlexSmith2019-11-20 3WilliamBrown2019-11-20 4AliceThomas2019-11-05 For each patient, let’s find the day of the medical visit. We’ll get it from the VisitDate field. Solution We’ll use the DAY() function. Here’s the query you would write: SELECT FirstName, LastNme, DAY(VisitDate) AS VisitDay FROM MedicalVisit; Here’s the result of the query: FirstNameLastNameVisitDay JaneMiller17 AlexSmith20 WilliamBrown20 AliceThomas5 Discussion If you want to get the number of day from a date in a table, use the SQL Server DAY() function. This function takes only one argument – the date. This can be a date or date and time data type. (In our example, the column VisitDate is of the date data type.) The argument can be a column name or an expression. (In our example, it is the VisitDate column.) DAY() returns the number of the day of the month as an integer from 1 to 31. For Alice Thomas’ visit, the day is 5; we get it from the YYYY-MM-DD date 2019-11-05. Recommended courses: SQL Basics in SQL Server Common Functions in SQL Server Recommended articles: SQL Server Cheat Sheet Top 29 SQL Server Interview Questions How to Learn T-SQL Querying 5 SQL Functions for Manipulating Strings 18 Useful Important SQL Functions to Learn ASAP Performing Calculations on Date- and Time-Related Values See also: How to Get the Year from a Date in T-SQL How to Get the Month from a Date in T-SQL Subscribe to our newsletter Join our monthly newsletter to be notified about the latest posts. Email address How Do You Write a SELECT Statement in SQL? What Is a Foreign Key in SQL? Enumerate and Explain All the Basic Elements of an SQL Query