SQL服务器 DATEPART() 函数
示例
返回日期的指定部分:
SELECT DATEPART(year, '2017/08/25') AS DatePartInt;
亲自试一试 »
定义和用法
DATEPART() 函数返回日期的指定部分。
该函数以整数值形式返回结果。
语法
DATEPART(
interval,
date)
参数值
Parameter |
Description |
interval |
Required. The part of the date argument to return. Can be one of the following values:
- year, yyyy, yy = Year
- quarter, qq, q = Quarter
- month, mm, m = month
- dayofyear, dy, y = Day of the year
- day, dd, d = Day of the month
- week, ww, wk = Week
- weekday, dw, w = Weekday
- hour, hh = hour
- minute, mi, n = Minute
- second, ss, s = Second
- millisecond, ms = Millisecond
- microsecond, mcs = Microsecond
- nanosecond, ns = Nanosecond
- tzoffset, tz = Timezone offset
- iso_week, isowk, isoww = ISO week
|
date |
Required. The date to use. Can be one of the following data types: date, datetime, datetimeoffset, datetime2, smalldatetime, or time |
技术细节
工作于: |
SQL Server(从 2008 年开始)、Azure SQL 数据库、Azure SQL 数据仓库、并行数据仓库 |
更多示例
示例
返回日期的指定部分:
SELECT DATEPART(yy, '2017/08/25') AS DatePartInt;
亲自试一试 »
示例
返回日期的指定部分:
SELECT DATEPART(month, '2017/08/25') AS DatePartInt;
亲自试一试 »
示例
返回日期的指定部分:
SELECT DATEPART(hour, '2017/08/25 08:36') AS DatePartInt;
亲自试一试 »
示例
返回日期的指定部分:
SELECT DATEPART(minute, '2017/08/25 08:36') AS DatePartInt;
亲自试一试 »