DAY (Transact-SQL)DAY (Transact-SQL)

適用於: 是SQL Server 是Azure SQL Database 是Azure SQL 資料倉儲 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

此函式會傳回整數,代表指定 date 的日期 (當月的日期)。This function returns an integer that represents the day (day of the month) of the specified date.

如需所有 Transact-SQLTransact-SQL 日期和時間資料類型與函式的概觀,請參閱日期和時間資料類型與函式 (Transact-SQL)See Date and Time Data Types and Functions (Transact-SQL) for an overview of all Transact-SQLTransact-SQL date and time data types and functions.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions


DAY ( date )  


可解析成下列其中一個資料類型的運算式:An expression that resolves to one of the following data types:

  • datedate
  • datetimedatetime
  • datetimeoffsetdatetimeoffset
  • datetime2datetime2
  • smalldatetimesmalldatetime
  • timetime

針對 dateDAY 會接受資料行運算式、運算式、字串常值或使用者定義變數。For date, DAY will accept a column expression, expression, string literal, or user-defined variable.

傳回類型Return Type


傳回值Return Value

DAY 會與 DATEPART (day, date) 傳回相同的值。DAY returns the same value as DATEPART (day, date).

如果 date 僅包含時間部分,DAY 會傳回 1 (基底日期)。If date contains only a time part, DAY will return 1 - the base day.


此陳述式會傳回 30 (日期數值本身)。This statement returns 30 - the number of the day itself.

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

此陳述式會傳回 1900, 1, 1This statement returns 1900, 1, 1. date 引數的數值為 0The date argument has a number value of 0. SQL ServerSQL Server 會將 0 解譯為 1900 年 1 月 1 日。interprets 0 as January 1, 1900.


另請參閱See also

CAST 和 CONVERT (Transact-SQL)CAST and CONVERT (Transact-SQL)