DATEPART
Syntax
DATEPART( datetime, unit [ , firstday ] )
Description
Returns a part of the date as an integer.
Depending on the argument, unit
returns the following values:
"year"
— the year number (see YEAR);"month"
— the number of the month in the year (see MONTH);"week"
— the number of the week in the year according to ISO 8601 (see WEEK);"dayofweek"
,"dow"
— the number of the day of the week (see DAYOFWEEK);"day"
— the number of the day in the month (see DAY);"hour"
— the number of the hour in the day (see HOUR);"minute"
— the number of the minute in the hour (see MINUTE);"second"
— the number of the second in the minute (see SECOND).
If you select "dayofweek"
, you can use the additional parameter firstday
to specify the first day of the week (Monday by default). Learn more about this parameter in the DAYOFWEEK function description.
Argument types:
datetime
—Date | Datetime
unit
—String
firstday
—String
Return type: Number (whole)
Note
Only constant values are accepted for arguments (firstday
).
Examples
DATEPART(#2019-01-23#, "year") = 2019
DATEPART(#2019-01-23#, "month") = 1
DATEPART(#2019-01-23#, "day") = 23
DATEPART(#2019-01-23 11:47:07#, "hour") = 11
DATEPART(#2019-01-23 11:47:07#, "minute") = 47
DATEPART(#2019-01-23 11:47:07#, "second") = 7
DATEPART(#1971-01-14 01:02:03#, "dayofweek") = 4
DATEPART(#1971-01-14 01:02:03#, "dayofweek", "wed") = 2
Data source support
Materialized Dataset
, ClickHouse 1.1
, Microsoft SQL Server 2017 (14.0)
, MySQL 5.6
, Oracle Database 12c (12.1)
, PostgreSQL 9.3
.