| 
     << Click to Display Table of Contents >> 日期时间函数 | 
    
    
     ![]() ![]()  
     | 
  
永洪产品提供了多种日期函数。请参见日期函数的语法表 。
此外,许多日期函数还使用 date_part,它是一个常量字符串参数。
有效 date_part 值为:
DATE_PART  | 
值  | 
|---|---|
year  | 
四位数年份  | 
quarter  | 
1-4  | 
month  | 
1-12 或 "January"、"February" 等  | 
hour  | 
0-23  | 
minute  | 
0-59  | 
second  | 
0-59  | 
dayofyear  | 
一年中的第几天;1 月 1 日为 1、2 月 1 日为 32,依此类推  | 
dayofmonth  | 
1-31  | 
dayofweek  | 
1-7 或 "Sunday"、"Monday" 等  | 
weekofyear  | 
1-52  | 
函数  | 
语法  | 
说明  | 
举例  | 
|---|---|---|---|
date  | 
date(year, month, day)  | 
通过数字生成日期值  | 
例如: date(2020,11,3) = 2020-11-03  | 
dateAdd  | 
dateAdd(date,date_part, interval)  | 
返回指定日期,该日期的指定 date_part中添加了指定的数字 interval,date_part的可选值为"year", "quarter", "month", "weekofyear","dayofyear", "dayofmonth","dayofweek", "hour", "minute", "second"  | 
例如: dateAdd(col['order_date'],'month', 3) 该表达式会向订单日期添加三个月  | 
dateGap  | 
dateGap(date1,date2, date_option) 
 
  | 
比较两个日期按照date_option的差值。date_option的参数有:year,quarter,month,weekofyear,dayofyear,dayofmonth,dayofweek,hour,minute,second  | 
例如: 假如col['order_date'] 是 2010-04-13,col['receive_date'] 是 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])  | 
返回日期的指定 date_part 的名称,date_part的可选值为"year","quarter","month", "weekofyear","dayofyear", "dayofmonth","dayofweek", "hour","minute","second",start_of_week的可选值为"monday","tuesday","wednesday","thursday","friday","saturday", "sunday"。如果省略不写start_of_week,则周的起始日是由数据源的配置决定  | 
例如: 假如时间是2021-04-25 18:30:00,则dateName(col['order_date'], 'Monday')=4  | 
datePart  | 
datePart(date,date_part) 
  | 
以整数的形式返回date的 date_part date_part的可选值为"year", "quarter", "month", "weekofyear", "dayofyear", "dayofmonth", "dayofweek", "hour", "minute", "second"  | 
例如: 假如col['order_date'] 是 2010-04-13 datePart(col['order_date'], 'year') = 2010 datePart(col['order_date'], 'month') = 4  | 
dateTrunc  | 
dateTrunc(date_part, date, [start_of_week]) 
 
  | 
按 date_part 指定的准确度截断指定日期 date_part的可选值为"year", "quarter", "month", "weekofyear", "dayofyear", "dayofmonth", "dayofweek", "hour", "minute", "second" start_of_week 可选参数,可选值为"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"  | 
例如: 假如col['order_date'] 是 2010-05-13 18:30:00 dateTrunc('quarter', col['order_date']) = 2010-04-01 00:00:00 dateTrunc('month', col['order_date']) = 2010-05-01 00:00:00  | 
dateValue  | 
dateValue(date)  | 
 返回到起始日期的天数,1900-01-01返回的是0 
  | 
例如: 假如col['order_date'] 是 2020-02-17 。 dateValue(col['order_date']) = 43876  | 
day  | 
day(date)  | 
 返回的是这个月的天数,值范围[1, 31] 
  | 
例如: 假如col['order_date'] 是 2010-04-13 day(col['order_date']) = 13  | 
getDate  | 
getDate(date)  | 
检测输入的参数是否是日期类型的,是返回参数,否返回null  | 
例如: getDate(col['order_date'])  | 
isDate  | 
isDate(date)  | 
检测输入的值或者列是否是日期类型的,返回true或者false  | 
例如: isDate(col['order_date'])  | 
month  | 
month(date)  | 
返回的月的数字表示,值范围[1, 12]  | 
例如: 假如col['order_date'] 是 2010-04-13 month(col['order_date']) = 4  | 
now  | 
now()  | 
返回服务器时间  | 
例如: now() = 2020-02-17 16:08:21  | 
quarter  | 
quarter(date)  | 
返回季度的数字表示,值范围[1, 4]  | 
例如: 假如col['order_date'] 是 2010-04-13 quarter(col['order_date']) = 2  | 
today  | 
 today() 
  | 
返回服务器日期  | 
例如: today() = 2020-02-17  | 
weekday  | 
weekday(date, [return_type])  | 
返回星期几的数字表示return_type 可选参数,如果设置值为数字1 或省略 则返回的值1 至7, 代表星期天到星期六;设置的数字是2 则返回的值为1 至7 ,代表星期一到星期天;如果设置的值为数字3,则返回的值为0至6,代表星期一到星期天  | 
例如: 假如col['order_date'] 是 2020-02-17 weekday(col['order_date']) = 2  | 
weekNum  | 
weekNum(date, [dayType])  | 
返回一年内的周数,dayType不传或者传2表示周一为一周的开始  | 
例如: 假如col['order_date'] 是 2020-02-17 weekNum(col['order_date']) = 8  | 
year  | 
year(date)  | 
返回年的数字表示  | 
例如: 假如col['order_date'] 是 2010-04-13 。 year(col['order_date']) = 2010  |