文档

公共日历内建函数

更新时间:

您可以在离线SQL任务中使用公共日历内建函数进行相关的日期计算。本文为您提供公共日历支持的内建函数的命令格式、参数说明及示例,指导您使用公共日历内建函数。

使用限制

仅支持在离线SQL代码中使用。

内建函数目录

公共日历支持的内建函数如下:

函数

功能

dpc_last_workday

计算离business_date最近的第day_offset个工作日。

dpc_last_label_date

计算离business_date最近的第day_offset个包含标签label_code的日期。

dpc_is_labelled

计算公共日历calendar_codebusiness_date是否有label_code标签。

dpc_is_workday

计算公共日历calendar_codebusiness_date是否为工作日。

dpc_last_workdays

计算公共日历calendar_code中在business_date之前,离business_date最近的periods个日/月/年周期内的所有工作日。

dpc_workdays

计算返回在公共日历calendar_code中在startdate(包含)之后,enddate(包含)之前的所有工作日。

dpc_last_labelled_workdays

计算在公共日历calendar_code中在business_date之前,离business_date最近的periods个日/月/年周期内的所有包含label_code标签的工作日。

dpc_labelled_workdays

计算在公共日历calendar_code中在startdate(包含)之后, enddate(包含)之前的所有lable_code标签的工作日。

dpc_last_workday

  • 命令格式

    string dpc_last_workday(string "calendar_code",string "business_date",int day_offset=1)
  • 命令说明

    计算离business_date最近的第day_offset个工作日。

  • 参数说明

    • calendar_code:公共日历编码,String类型。

    • label_code:标签编码,String类型。

    • business_date:任意业务日期,String类型,格式为yyyyMMdd。

    • periods:周期个数,Int类型,默认为1,有效值为1d <= day_offset <= 7305d(20 年)1m <= day_offset <= 240m1y <= day_offset <= 20y

    • timeFormat:周期类型,默认为d,允许的类型有:

      • 日:d

      • 月:m

      • 年:y

  • 返回值说明

    返回在公共日历calendar_code中在business_date之前,离business_date最近periods个日\月\年周期内的所有包含label_code标签的工作日。如果business_date本身就是工作日,则business_date算作第 1 个工作日。

  • 示例:

    select dpc_last_labelled_workdays('finance_calendar','chrismas_day' ,'20231126'); --返回 20231124
    select dpc_last_labelled_workdays('finance_calendar', 'chrismas_day' ,'20231127'); --返回 20231127
    select dpc_last_labelled_workdays('finance_calendar', 'chrismas_day' ,'20231127', 5); --返回 20231121,20231122,20231123,20231124,20231125
    select dpc_last_labelled_workdays('finance_calendar', 'chrismas_day' ,'20231127', m, 1); --返回 20231030...20231127

dpc_last_label_date

  • 命令格式:

    string dpc_last_label_date(string "calendar_code",string "business_date",string "label_code",int day_offset=1)
  • 命令说明

    计算离business_date最近的第day_offset个包含标签label_code的日期。

  • 参数说明

    • calendar_code: 公共日历编码, String类型。

    • business_date: 任意业务日期,String类型,格式为yyyyMMdd

    • label_code:标签编码,String类型。

    • day_offset:最近的第几个日期,Int类型,默认为1,有效值为1 <= day_offset <= 7305(20 年)

  • 返回值说明

    返回在公共日历calendar_code中在business_date之前,离business_date最近第day_offset个包含标签label_code的日期。如果business_date本身就包含标签label_code,则business_date为第1个日期。返回类型为String,格式为yyyyMMdd

  • 示例:

    select dpc_last_label_date('finance_calendar', '20231230', 'chrismas_day'); --返回 20231225
    select dpc_last_label_date('finance_calendar', '20231225', 'chrismas_day'); --返回 20231225
    select dpc_last_label_date('finance_calendar', '20231230', 'chrismas_day', 2); --返回 20221225

dpc_is_labelled

  • 命令格式:

    boolean dpc_is_labelled(string "calendar_code",string "business_date",string "label_code")
  • 命令说明

    计算公共日历calendar_codebusiness_date是否有label_code标签。

  • 参数说明

    • calendar_code:公共日历编码,String类型。

    • business_date:任意业务日期,String类型,格式为yyyyMMdd

    • label_code:标签编码,String类型

  • 返回值说明

    返回在公共日历calendar_codebusiness_date是否有label_code标签,有该标签返回 True,无则返回False

  • 示例:

    select dpc_is_labelled('finance_calendar', '20231225', 'chrismas_day'); --返回 True

dpc_is_workday

  • 命令格式

    boolean dpc_is_workday(string "calendar_code",string "business_date")
  • 命令说明

    计算公共日历calendar_codebusiness_date是否为工作日。

  • 参数说明

    • calendar_code:公共日历编码,String类型。

    • business_date:任意业务日期,String类型,格式为yyyyMMdd

  • 返回值说明

    返回在公共日历calendar_codebusiness_date是否为工作日,是工作日则返回True,为假日则返回False

  • 示例:

    select dpc_is_workday('finance_calendar', '20231128'); --返回 True
    select dpc_is_workday('finance_calendar', '20231202'); --返回 False

dpc_last_workdays

  • 命令格式:

    string dpc_last_workdays(string <calendar_code>,string <business_date>,int <periods>, string <timeFormat>)
  • 命令说明

    计算公共日历calendar_code中在business_date之前,离business_date最近的periods个日/月/年周期内的所有工作日。

  • 参数说明

    • calendar_code:公共日历编码,String类型。

    • business_date:任意业务日期,String类型,格式为yyyyMMdd

    • periods:周期个数,Int类型,默认为1,有效值为1d <= day_offset <= 7305d(20 年)1m <= day_offset <= 240m1y <= day_offset <= 20y

    • timeFormat:周期类型,默认为d,允许的类型有:

      • 日:d

      • 月:m

      • 年:y

  • 返回值说明

    返回在公共日历calendar_code中在business_date之前,离business_date最近periods个日/月/年周期内的所有工作日。如果business_date本身就是工作日,则business_date算作第1个工作日。

  • 示例:

    select dpc_last_workdays('finance_calendar', '20231126'); --返回 20231124
    select dpc_last_workdays('finance_calendar', '20231127'); --返回 20231127
    select dpc_last_workdays('finance_calendar', '20231127', 5); --返回20231121,20231122,20231123,20231124,20231125
    select dpc_last_workdays('finance_calendar', '20231127', m, 1); --返回 20231030...20231127

dpc_workdays

  • 命令格式

    string dpc_workdays(string <calendar_code>,string <startdate>,string <enddate>)
  • 命令说明

    计算返回在公共日历calendar_code中在startdate(包含)之后,enddate(包含)之前的所有工作日。

  • 参数说明

    • calendar_code: 公共日历编码,String类型。

    • startdate: 任意起始业务日期,String类型,格式为yyyyMMdd

    • enddate: 任意结束业务日期,String类型,格式为yyyyMMdd

      重要

      有效值为enddate - startdate <= 20年

  • 返回值说明

    返回在公共日历calendar_code中在startdate(包含)之后, enddate(包含)之前,的所有工作日。如果business_date本身就是工作日,则business_date算作第 1 个工作日。

  • 示例:

    select dpc_workdays('finance_calendar', '20231124', '20231126'); --返回 20231124
    select dpc_workdays('finance_calendar', '20231126', '20231127'); --返回 20231127

dpc_last_labelled_workdays

  • 命令格式:

    string dpc_last_labelled_workdays(string <calendar_code>,string <label_code>,string <business_date>,int <periods>, string <timeFormat>)
  • 命令说明

    计算在公共日历calendar_code中在business_date之前,离business_date最近的periods个日/月/年周期内的所有包含label_code标签的工作日。

  • 参数说明

    • calendar_code:公共日历编码,String类型。

    • label_code:标签编码,String类型。

    • business_date:任意业务日期,String类型,格式为yyyyMMdd。

    • periods:周期个数,Int类型,默认为1,有效值为1d <= day_offset <= 7305d(20 年)1m <= day_offset <= 240m1y <= day_offset <= 20y

    • timeFormat:周期类型,默认为d,允许的类型有:

      • 日:d

      • 月:m

      • 年:y

  • 返回值说明

    返回在公共日历calendar_code中在business_date之前,离business_date最近periods个日/月/年周期内的所有包含label_code标签的工作日。如果business_date本身就是工作日,则business_date算作第1个工作日。

  • 示例:

    select dpc_last_labelled_workdays('finance_calendar','chrismas_day' ,'20231126'); --返回 20231124
    select dpc_last_labelled_workdays('finance_calendar', 'chrismas_day' ,'20231127'); --返回 20231127
    select dpc_last_labelled_workdays('finance_calendar', 'chrismas_day' ,'20231127', 5); --返回 20231121,20231122,20231123,20231124,20231125
    select dpc_last_labelled_workdays('finance_calendar', 'chrismas_day' ,'20231127', m, 1); --返回 20231030...20231127

dpc_labelled_workdays

  • 命令格式:

    string dpc_labelled_workdays(string <calendar_code>,string <label_code>,string <startdate>,string <enddate>)
  • 命令说明

    计算在公共日历calendar_code中在startdate(包含)之后,enddate(包含)之前的所有lable_code标签的工作日。

  • 参数说明

    • calendar_code: 公共日历编码,String类型。

    • label_code: 标签编码,String类型。

    • startdate: 任意起始业务日期,String类型,格式为yyyyMMdd

    • enddate: 任意结束业务日期,String类型,格式为yyyyMMdd

      重要

      有效值为enddate - startdate <= 20年

  • 返回值说明

    返回在公共日历calendar_code中在startdate(包含)之后, enddate(包含)之前,的所有lable_code标签的工作日。如果business_date本身就是工作日,则business_date算作第1个工作日。

  • 示例:

    select dpc_labelled_workdays('finance_calendar','chrismas_day','20231124', '20231126'); --返回 20231124,20231126
    select dpc_labelled_workdays('finance_calendar','chrismas_day', '20231126', '20231127'); --返回 20231126,20231127
  • 本页导读