[GBase 8s 教程]GBase 8s 时间/日期函数和操作符
日期/时间操做符
下表演示了基本算术操作符的行为(+,-,*,/等):
类型1 | 操作符 | 类型2 | 返回类型 | 示例、说明 |
---|---|---|---|---|
DATE | - | DATE | INTERVAL DAY TO DAY | date('2020-05-08') - date('2020-05-01') 值为7 |
DATE | - | DATETIME | INTERVAL DAY TO DAY | date('2020-05-08') - datetime(2020-05-01 12:00:00) year to second 值为7 |
DATE | + - | INTERVAL DAY TO DAY | DATETIME | date('2020-05-08') + interval(10) day to day 值为2020-05-18 00:00:00 |
DATE | + - | NUMBER | DATE | date('2020-05-08') - 10 值为2020-04-28 |
DATETIME | - | DATE | INTERVAL | current year to second - date('2020-05-08')值为 0 20:46:57 当前时间为2020-05-08 20:46:57,将DATE类型转换为当天00:00:00 |
DATETIME | - | DATETIME | INTERVAL | current year to second - datetime(2020-05-01 12:58:58) year to second 值为 7 07:50:05 |
DATETIME | + - | INTERVAL | DATETIME | current year to second - interval(03:04:05) hour to second 值为2020-05-08 17:46:02 |
DATETIME | + - | NUMBER | DATETIME | current year to second + 2/24/60 值为2020-05-08 21:07:17 当前时间为2020-05-08 21:05:17,2/24/60 (2分钟) |
INTERVAL | + - | INTERVAL | INTERVAL | interval(03:04:05) hour to second + interval(3) hour to hour 值为 6:04:05 |
INTERVAL | * / | NUMBER | INTERVAL | interval(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 |
TODAY | DATE | 返回当前日期的日期值 | TODAY | 2020-05-08 |
CURRENT [first TO last] | DATETIME | 返回当时日期的日期时间值 | CURRENT YEAR TO SECOND | 2020-05-08 21:22:09 |
SYSDATE [first TO last] | DATETIME | 返回当时日期的日期时间值 | SYSDATE YEAR TO SECOND | 2020-05-08 21:22:09 |
MDY(Month,Day,Year) | DATE | 返回指定的日期值 | MDY(5,8,2020) | 2020-05-08 |
DATETIME(date/datetime) first TO last | DATETIME | 返回表达式代表的日期时间值 | datetime(2020-05-08 20:10:50) year to second | 2020-05-08 20:10:50 |
INTERVAL(date/datetime) first TO last | INTERVAL | 返回表达式代表的间隔值 | interval(3 03:04:05) day to second | 3 03:04:05 |
EXTEND(date/datetime,[first TO last]) | DATETIME | 返回经过表达式调整的日期时间值 | extend(current year to second, hour to second) | 21:33:06 |
已有 2 条评论