本文为您介绍如何使用实时计算日期函数EXTRACT。

语法

BIGINT EXTRACT(unit FROM time)

入参

参数 数据类型
time 任意日期表达式。
unit 可取值如下:
  • MICROSECOND
  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • WEEK
  • MONTH
  • QUARTER
  • YEAR
  • SECOND_MICROSECOND
  • MINUTE_MICROSECOND
  • MINUTE_SECOND
  • HOUR_MICROSECOND
  • HOUR_SECOND
  • HOUR_MINUTE
  • DAY_MICROSECOND
  • DAY_SECOND
  • DAY_MINUTE
  • DAY_HOUR
  • YEAR_MONTH

功能描述

返回日期/时间的单独部分,例如年、月、日、小时、分钟、周数等。

示例

  • 测试语句
    EXTRACT(YEAR FROM CURRENT_TIMESTAMP) AS OrderYear,
    EXTRACT(MONTH FROM CURRENT_TIMESTAMP) AS OrderMonth,
    EXTRACT(DAY FROM CURRENT_TIMESTAMP) AS OrderDay,
    EXTRACT(WEEK FROM CURRENT_TIMESTAMP) AS OrderWeek    
  • 测试结果
    OrderYear(BIGINT) OrderMonth(BIGINT) OrderDay(BIGINT) OrderWeek(BIGINT)
    2018 10 11 41