全部產品
Search
文件中心

Dataphin:公用日曆內建函數

更新時間:Jan 25, 2025

您可以在離線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類型。

    • business_date:任意業務日期,String類型,格式為yyyyMMdd。

    • day_offset:最近的第幾個工作日,int類型,有效值為1 <= day_offset <= 7305(20年),預設值為1。

  • 傳回值說明

    返回在公用日曆calendar_code中在business_date之前,離business_date最近的第day_offset個工作日。如果business_date本身就是工作日,則business_date算作第 1 個工作日。傳回型別為String,格式為yyyyMMdd。

  • 樣本:

    select dpc_last_workday('finance_calendar', '20231126'); --返回 20231124
    select dpc_last_workday('finance_calendar', '20231127'); --返回 20231127
    select dpc_last_workday('finance_calendar', '20231127', 5); --返回 20231121

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