Skip to content

Latest commit

 

History

History
95 lines (70 loc) · 3.1 KB

File metadata and controls

95 lines (70 loc) · 3.1 KB
title DAY (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 07/30/2017
ms.prod sql-non-specified
ms.reviewer
ms.suite
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
DAY_TSQL
DAY
dev_langs
TSQL
helpviewer_keywords
date and time [SQL Server], DAY
dates [SQL Server], functions
DAY function [SQL Server]
dates [SQL Server], days
functions [SQL Server], date and time
dateparts [SQL Server], day
ms.assetid 2f4410ea-fd3e-4d69-ac4b-3b0091a084bc
caps.latest.revision 41
author BYHAM
ms.author rickbyh
manager jhubbard

DAY (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-all_md]

Returns an integer representing the day (day of the month) of the specified date.

For an overview of all [!INCLUDEtsql] date and time data types and functions, see Date and Time Data Types and Functions (Transact-SQL).

Topic link icon Transact-SQL Syntax Conventions

Syntax

-- Syntax for SQL Server, Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse  
  
DAY ( date )  

Arguments

date
Is an expression that can be resolved to a time, date, smalldatetime, datetime, datetime2, or datetimeoffset value. The date argument can be an expression, column expression, user-defined variable or string literal.

Return Type

int

Return Value

DAY returns the same value as DATEPART (day, date).

If date contains only a time part, the return value is 1, the base day.

Examples

The following statement returns 30. This is the number of the day.

SELECT DAY('2015-04-30 01:01:01.1234567');  

The following statement returns 1900, 1, 1. The argument for date is the number 0. [!INCLUDEssNoVersion] interprets 0 as January 1, 1900.

SELECT YEAR(0), MONTH(0), DAY(0);  

Examples: [!INCLUDEssSDWfull] and [!INCLUDEssPDW]

The following example returns 30. This is the number of the day.

-- Uses AdventureWorks  
  
SELECT TOP 1 DAY('2010-07-30T01:01:01.1234')   
FROM dbo.DimCustomer;  

The following example returns 1900, 1, 1. The argument for date is the number 0. [!INCLUDEssNoVersion] interprets 0 as January 1, 1900.

-- Uses AdventureWorks  
  
SELECT TOP 1 YEAR(0), MONTH(0), DAY(0) FROM dbo.DimCustomer;  

See also

CAST and CONVERT (Transact-SQL)