DAY function in SQL Server

The DAY function in SQL Server returns an integer that is the day of the month (from 1 to 31) from the time passed.

This article will show you in detail how to use DAY () DateTime () function in SQL Server with specific syntax and examples to better visualize and capture functions.

Describe

The DAY function in SQL Server returns an integer that is the day of the month (from 1 to 31) from the time passed.

Syntax

To use DAY function in SQL Server, we use the following syntax:

 DAY(thoigian) 

Parameters :

  1. thoigian: the time you want to retrieve the date value.

Note :

  1. The DAY function returns the result as an integer value.
  2. See also the DATENAME and DATEPART functions that return similar results.
  3. DAY can be used in later versions of SQL Server: SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, and SQL Server 2005.

For example

Take a look and explore some examples of DAY functions in SQL Server.

 SELECT DAY('2019/04/28'); 
Result: 28

SELECT DAY('2019/03/31 10:05');
Result: 31

SELECT DAY('2019/04/01 10:05:18.621');
Result: 1

Previous article: DATEPART function in SQL Server

Next article: GETDATE function in SQL Server

4 ★ | 2 Vote