Public calendar built-in functions

Updated at:

Public calendar built-in functions facilitate date calculations in offline SQL tasks. This topic outlines the syntax, parameters, and examples for the functions supported by the public calendar, providing guidance for their use.

Limits

Supported exclusively in offline SQL code.

Built-in function directory

The public calendar supports the following built-in functions:

Function

Feature

dpc_last_workday

Calculates the nearest day_offset workday from the business_date.

dpc_last_label_date

Calculates the nearest day_offset date containing the label_code from the business_date.

dpc_is_labelled

Calculates whether the business_date in the public calendar calendar_code has the label_code tag.

dpc_is_workday

Calculates whether the business_date in the public calendar calendar_code is a workday.

dpc_last_workdays

Calculate all working days within the periods day/month/year cycles closest to the business_date before the business_date in the public calendar calendar_code.

dpc_workdays

Calculates and returns all workdays between startdate (inclusive) and enddate (inclusive) in the public calendar calendar_code.

dpc_last_labelled_workdays

Calculate all working days that contain the label_code tag within the periods day/month/year cycles closest to the business_date before the business_date in the public calendar calendar_code.

dpc_labelled_workdays

Calculates all workdays containing the label_code tag between startdate (inclusive) and enddate (inclusive) in the public calendar calendar_code.

dpc_last_workday

  • Command Syntax:

    string dpc_last_workday(string "calendar_code", string "business_date", int day_offset=1)
  • Command Description:

    Calculates the nearest workday to the specified business_date, based on the given day_offset.

  • Parameter Description:

    • calendar_code: Identifier for the public calendar, String type.

    • business_date: The reference date, String type, in the format yyyyMMdd.

    • day_offset: Number of workdays to calculate from the business_date, Int type. Acceptable values range from 1 <= day_offset <= 7305 (20 years), with a default of 1.

  • Return Value Description:

    Returns the day_offsetth business day closest to business_date before business_date in the public calendar calendar_code. If business_date itself is a business day, then business_date is considered the first business day. The return type is String, formatted as yyyyMMdd.

  • Example:

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

dpc_last_label_date

  • Command Syntax:

    string dpc_last_label_date(string "calendar_code", string "business_date", string "label_code", int day_offset=1)
  • Command Description:

    Determines the closest date to business_date that includes the label_code, offset by day_offset.

  • Parameter Description:

    • calendar_code: Identifier for the public calendar, String type.

    • The business_date parameter represents any data timestamp in String format, specified as yyyyMMdd.

    • label_code: Identifier for the tag, String type.

    • day_offset: Number of days to calculate from the business_date, Int type. Acceptable values range from 1 <= day_offset <= 7305 (20 years), with a default of 1.

  • Return Value Description:

    Returns the date in the public calendar calendar_code that is the closest to business_date before business_date, which is the day_offsetth date containing the tag label_code. If business_date itself contains the tag label_code, then business_date is considered the first date. The return type is String, formatted as yyyyMMdd.

  • Example:

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

dpc_is_labelled

  • Command Syntax:

    boolean dpc_is_labelled(string "calendar_code", string "business_date", string "label_code")
  • Command Description:

    Determines if the business_date within the public calendar calendar_code is tagged with label_code.

  • Parameter Description:

    • calendar_code: Identifier for the public calendar, String type.

    • business_date: A data timestamp of the String type, formatted as yyyyMMdd.

    • label_code: The tag encoding, of type String.

  • Return Value Description:

    Indicates whether the business_date includes the label_code tag within the calendar_code. Returns True if the tag is present, otherwise False.

  • Example:

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

dpc_is_workday

  • Command Syntax:

    boolean dpc_is_workday(string "calendar_code", string "business_date")
  • Command Description:

    Determines if the business_date within the public calendar calendar_code is a business day.

  • Parameter Description:

    • calendar_code: Identifier for the public calendar, String type.

    • business_date: A data timestamp of the String type, formatted as yyyyMMdd.

  • Return Value Description:

    Indicates whether the business_date is a workday within the calendar_code. Returns True for a workday, otherwise False for a holiday.

  • Example:

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

dpc_last_workdays

  • Command Syntax:

    string dpc_last_workdays(string <calendar_code>, string <business_date>, int <periods>, string <timeFormat>)
  • Command Description:

    Calculate all working days within the periods day/month/year cycles closest to the business_date before the business_date in the public calendar calendar_code.

  • Parameter Description:

    • calendar_code: Identifier for the public calendar, String type.

    • business_date: A data timestamp of the String type, formatted as yyyyMMdd.

    • periods: Number of cycles, Int type. Acceptable values range from 1d <= day_offset <= 7305d (20 years), 1m <= day_offset <= 240m, or 1y <= day_offset <= 20y, with a default of 1.

    • timeFormat: Cycle type, with a default of d. Allowed types are:

      • Day: d.

      • Month: m.

      • Year: y.

  • Return Value Description:

    Returns all working days within the periods day/month/year cycles closest to business_date before business_date in the public calendar calendar_code. If business_date itself is a working day, business_date is counted as the first working day.

  • Example:

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

dpc_workdays

  • Command Syntax:

    string dpc_workdays(string <calendar_code>, string <startdate>, string <enddate>)
  • Command Description:

    Calculates all workdays between the startdate (inclusive) and enddate (inclusive) within the calendar_code.

  • Parameter Description:

    • calendar_code: Identifier for the public calendar, String type.

    • startdate: A starting date timestamp of the String type, with the format yyyyMMdd.

    • enddate: A String type representing any end date timestamp, formatted as yyyyMMdd.

      Important

      The range between enddate and startdate must not exceed 20 years.

  • Return Value Description:

    Returns all workdays between startdate (inclusive) and enddate (inclusive) in the public calendar calendar_code. If the business_date itself is a workday, then business_date is considered the first workday.

  • Example:

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

dpc_last_labelled_workdays

  • Command Syntax:

    string dpc_last_labelled_workdays(string <calendar_code>, string <label_code>, string <business_date>, int <periods>, string <timeFormat>)
  • Command Description:

    Calculate all working days that contain the label_code tag within the periods day/month/year cycles closest to the business_date before the business_date in the public calendar calendar_code.

  • Parameter Description:

    • calendar_code: Identifier for the public calendar, String type.

    • label_code: Identifier for the tag, String type.

    • business_date: The reference date timestamp, String type, in the format yyyyMMdd.

    • periods: Number of cycles, Int type. Acceptable values range from 1d <= day_offset <= 7305d (20 years), 1m <= day_offset <= 240m, or 1y <= day_offset <= 20y, with a default of 1.

    • timeFormat: Cycle type, with a default of d. Allowed types are:

      • Day: d.

      • Month: m.

      • Year: y.

  • Return Value Description:

    Returns all working days that contain the label_code tag within the periods day/month/year cycles closest to the business_date in the public calendar calendar_code before the business_date. If the business_date itself is a working day, then business_date is counted as the first working day.

  • Example:

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

dpc_labelled_workdays

  • Command Syntax:

    string dpc_labelled_workdays(string <calendar_code>, string <label_code>, string <startdate>, string <enddate>)
  • Command Description:

    Determines all weekdays marked with the calendar_code tag that fall between startdate and enddate, inclusive, within the specified public calendar calendar_code.

  • Parameter Description:

    • calendar_code: Identifier for the public calendar, String type.

    • label_code: Identifier for the tag, String type.

    • startdate: A starting date timestamp of type String, formatted as yyyyMMdd.

    • enddate: A String type representing any end date timestamp, formatted as yyyyMMdd.

      Important

      The range between enddate and startdate must not exceed 20 years.

  • Return Value Description:

    Returns all workdays containing the label_code tag between startdate (inclusive) and enddate (inclusive) in the public calendar calendar_code. If the business_date itself is a workday, then business_date is considered the first workday.

  • Example:

    select dpc_labelled_workdays('finance_calendar','chrismas_day','20231124', '20231126'); --Returns 20231124,20231126
    select dpc_labelled_workdays('finance_calendar','chrismas_day', '20231126', '20231127'); --Returns 20231126,20231127