[GBase 8s 教程]GBase 8s 时间/日期函数和操作符

日期/时间操做符

下表演示了基本算术操作符的行为(+,-,*,/等):

类型1操作符类型2返回类型示例、说明
DATE-DATEINTERVAL DAY TO DAYdate('2020-05-08') - date('2020-05-01') 值为7
DATE-DATETIMEINTERVAL DAY TO DAYdate('2020-05-08') - datetime(2020-05-01 12:00:00) year to second 值为7
DATE+ -INTERVAL DAY TO DAYDATETIMEdate('2020-05-08') + interval(10) day to day 值为2020-05-18 00:00:00
DATE+ -NUMBERDATEdate('2020-05-08') - 10 值为2020-04-28
DATETIME-DATEINTERVALcurrent year to second - date('2020-05-08')值为 0 20:46:57
当前时间为2020-05-08 20:46:57,将DATE类型转换为当天00:00:00
DATETIME-DATETIMEINTERVALcurrent year to second - datetime(2020-05-01 12:58:58) year to second 值为 7 07:50:05
DATETIME+ -INTERVALDATETIMEcurrent year to second - interval(03:04:05) hour to second 值为2020-05-08 17:46:02
DATETIME+ -NUMBERDATETIMEcurrent year to second + 2/24/60 值为2020-05-08 21:07:17
当前时间为2020-05-08 21:05:17,2/24/60 (2分钟)
INTERVAL+ -INTERVALINTERVALinterval(03:04:05) hour to second + interval(3) hour to hour 值为 6:04:05
INTERVAL* /NUMBERINTERVALinterval(03:04:05) hour to second * 4 值为12:16:20

日期/时间函数

函数返回类型描述示例结果
DAY(date/datetime)NUMBER返回第几天DAY(today)8 今天为2020-05-08
MONTH(date/datetime)NUMBER返回月份MONTH(today)5 今天为2020-05-08
YEAR(date/datetime)NUMBER返回年份YEAR(today)2020 今天为2020-05-08
WEEKDAY(date/datetime)NUMBER返回当周几WEEKDAY(today)5 今天为2020-05-08周五, 周日返回为0
DATE(date_string)DATE返回字符串日期date('2020-05-08')2020-05-08
TODAYDATE返回当前日期的日期值TODAY2020-05-08
CURRENT [first TO last]DATETIME返回当时日期的日期时间值CURRENT YEAR TO SECOND2020-05-08 21:22:09
SYSDATE [first TO last]DATETIME返回当时日期的日期时间值SYSDATE YEAR TO SECOND2020-05-08 21:22:09
MDY(Month,Day,Year)DATE返回指定的日期值MDY(5,8,2020)2020-05-08
DATETIME(date/datetime) first TO lastDATETIME返回表达式代表的日期时间值datetime(2020-05-08 20:10:50) year to second2020-05-08 20:10:50
INTERVAL(date/datetime) first TO lastINTERVAL返回表达式代表的间隔值interval(3 03:04:05) day to second3 03:04:05
EXTEND(date/datetime,[first TO last])DATETIME返回经过表达式调整的日期时间值extend(current year to second, hour to second)21:33:06

标签: interval, GBase, 日期操作, 时间操作, datetime

已有 2 条评论

  1. Mr_Suxsong Mr_Suxsong
    本教程中的时间函数,在执行时, 总是提示错误“invalid year in date”
    1. 有些函数的需要输入格式,需要指定DBDATE环境变量,例如:export DBDATE=Y4MD- 格式是2021-12-27

添加新评论