DAY

The SQL DAY function is used to extract the day component from a given date value. It returns an integer value representing the day of the month. The DAY function is available in many popular database management systems such as MySQL, SQL Server, Oracle, and PostgreSQL.

Syntax

The syntax of the DAY function is straightforward. It takes a date expression as its input and returns the day component of that date as an integer value. The general syntax of the DAY function is:

DAY(date)

Where date is the input date expression.

Example

For example, let’s say we have a table sales with the following data:

ID SaleDate
1 2023-01-01
2 2023-02-14
3 2023-03-25

If we want to extract the day component from the SaleDate column, we can use the DAY function as follows:

SELECT 
DAY(SaleDate) as SaleDay
FROM sales;

This will return the following result:

SaleDay
1
14
25

As you can see, the DAY function has extracted the day component from the SaleDate column and returned it as an integer value.

In conclusion, the SQL DAY function is a useful tool for working with date values in SQL queries. It allows you to extract the day component from a date value and use it in your queries for further analysis or manipulation.