<< Click to Display Table of Contents >> DateTime |
Yonghong provides a variety of date functions. See the syntax of the date functions.
In addition, many date functions use date_part, which is a constant string parameter.
The valid date_part values :
DATE_PART |
Value |
---|---|
year |
Four digit year |
quarter |
1-4 |
month |
1-12 or "January", "February", etc |
hour |
0-23 |
minute |
0-59 |
second |
0-59 |
dayofyear |
The day of the year; January 1 is January, February 1 is 32, etc |
dayofmonth |
1-31 |
dayofweek |
1-7 or "Sunday", "Monday", etc |
weekofyear |
1-52 |
The syntax for the date functions table:
Functions |
Syntax |
Instructions |
Examples |
---|---|---|---|
date |
date(year, month, day) |
Generate a date value from a number |
For example: date(2020,11,3) = 2020-11-03 |
dateAdd |
dateAdd(date,date_part, interval) |
Returns the specified date with the specified number interval added to the specified date_part of the date. The optional values for date_part are "year", "quarter", "month", "weekofyear", "dayofyear", "dayofmonth", "dayofweek" , "hour", "minute", "second" |
For example: dateAdd(col['order_date'],'month', 3) This expression adds three months to the order date |
dateGap |
dateGap(date1,date2, date_option) |
Compares the difference between two dates by date_option. The parameters of date_option are: year, quarter, month, weekofyear, dayofyear, dayofmonth, dayofweek, hour, minute, second |
For example: If col ['order_date'] is 2010-04-13, col ['receive_date'] is 2010-04-19 dateGap (col ['order_date'], col ['receive_date'], 'month') = 0 dateGap (col ['order_date'], col ['receive_date'], 'dayofmonth') = 6 |
dateName |
dateName(date, date_part, [start_of_week]) |
Returns the name of the specified date_part for the date. The optional values for date_part are "year", "quarter", "month", "weekofyear", "dayofyear", "dayofmonth", "dayofweek", "hour", "minute", "second", the optional values of startOfWeek are "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". The nstart_of_week parameter (can be used to specify which day is the first day of the week) is optional. Possible values are "monday", "tuesday" |
For example: If the time is 2021-04-25 18:30:00, then dateName (col ['order_date'], 'Monday') = 4 |
datePart |
datePart(date,date_part)
|
Returns date_part of date as an integer. date_part The optional values are "year", "quarter", "month", "weekofyear", "dayofyear", "dayofmonth", "dayofweek", "hour", "minute", "second" |
For example: If col ['order_date'] is 2010-04-13 datePart (col ['order_date'], 'year') = 2010 datePart (col ['order_date'], 'month') = 4 |
dateTrunc |
dateTrunc(date_part, date, [start_of_week]) |
Truncate the specified date with the accuracy specified by date_part. This function returns the new date. For example, when truncating a date in the middle of a month at the month level, this function returns the first day of the month. The start_of_week parameter (which can be used to specify which day is the first day of the week) is optional. Possible values are "monday", "tuesday", and so on. |
For example: If col ['order_date'] is 2010-05-13 18:30:00 dateTrunc ('quarter', col ['order_date']) = 2010-04-01 00: 00: 00 ndateTrunc ('month', col ['order_date']) = 2010-05-01 00: 00: 00 |
dateValue |
dateValue(date) |
Returns the number of days to the start date. 1900-01-01 returns 1.
|
For example: If col ['order_date'] is 2020-02-17. dateValue (col ['order_date']) = 43877 |
day |
day(date) |
returns the number of days in the month, value range [1, 31] |
For example: Suppose col ['order_date'] is 2010-04-13 day (col ['order_date']) = 13 |
getDate |
getDate(date) |
Checks whether the input parameter is a date type, returns a parameter, or returns null |
For example: getDate(col['order_date']) |
isDate |
isDate(date) |
Checks whether the input parameter is date type and returns true or false |
For example: isDate(col['order_date']) |
month |
month(date) |
Represents the number of months in the range [1, 12] |
For Example: If col ['order_date'] is 2010-04-13 month(col ['order_date']) = 4. |
now |
now() |
Returns the server time |
For example: now() = 2020-02-17 16:08:21 |
quarter |
quarter(date) |
Returns the numerical representation of the quarter, value range [1, 4] |
For example: Suppose col ['order_date'] is 2010-04-13 quarter(col ['order_date']) = 2 |
today |
today()
|
Returns the server date |
For example: today() = 2020-02-17 |
weekday |
weekday(date, [return_type]) |
Returns a numeric representation of the day of the week. |
For example: If col ['order_date'] is 2020-02-17 weekday(col ['order_date']) = 2 |
weekNum |
weekNum(date, [dayType]) |
Returns the number of weeks in a year. DayType is not passed or 2 indicates that Monday is the start of the week |
For example: If col['order_date'] is 2020-02-17 weekNum(col['order_date']) = 8 |
year |
year(date) |
Returns the number representation of the year |
For example: If col['order_date'] is 2010-04-13 。 year(col['order_date']) = 2010 |