The public calendar's built-in functions facilitate date calculations in offline SQL tasks. This topic outlines the command syntax, parameter descriptions, and examples for these functions, providing guidance for their application.
Limits
Available exclusively for offline SQL code.
Directory of built-in functions
Supported built-in functions of the public calendar include:
Function | Feature |
Calculates the closest workday to the specified | |
Determines the closest date with the specified | |
Checks if the | |
Determines if the | |
Calculates all workdays within the nearest | |
Lists all workdays between | |
Calculate all working days with the | |
Computes all workdays bearing the |
dpc_last_workday
Command syntax:
string dpc_last_workday(string "calendar_code", string "business_date", int day_offset=1)Command description:
Computes the nearest workday to the given
business_datebased on theday_offset.Parameter description:
calendar_code: Identifier for the public calendar, String type.
label_code: Identifier for the label, String type.
business_date: Any business date, String type, in the format yyyyMMdd.
periods: The number of cycles, Integer type, with a default of
1. Valid ranges are1d <= day_offset <= 7305d (20 years),1m <= day_offset <= 240m, or1y <= day_offset <= 20y.timeFormat: The type of cycle, with a default of
d. Permitted types are:Day:
d.Month:
m.Year:
y.
Return value description:
Returns all working days with the
label_codetag within theperiodsday/month/year cycles closest tobusiness_datebeforebusiness_datein the public calendarcalendar_code. Ifbusiness_dateitself is a working day, thenbusiness_dateis considered the 1st 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_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:
Identifies the closest date with the
label_codeto thebusiness_date, based on theday_offset.Parameter description:
calendar_code: Identifier for the public calendar, String type.
business_date: A String representing any business date, formatted as
yyyyMMdd.label_code: Identifier for the label, String type.
day_offset: The number of days to the nearest date, Integer type, with a default of
1. Valid ranges are1 <= day_offset <= 7305 (20 years).
Return value description:
Returns the nearest
day_offsetdate with the labellabel_codebefore thebusiness_datein the public calendarcalendar_code. If thebusiness_dateitself contains the labellabel_code, thenbusiness_dateis the first date. Return type is String, format isyyyyMMdd.yyyyMMddExample:
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:
Checks whether the
business_datein the public calendarcalendar_codeis associated with thelabel_code.Parameter description:
calendar_code: The code representing the public calendar, String type.
business_date: A String representing any business date, formatted as
yyyyMMdd.label_code: Tag encoding, String type.
Return value description:
Indicates whether the
business_datein the public calendarcalendar_codecarries thelabel_code. It returnsTrueif the label is present, otherwiseFalse.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_datein the public calendarcalendar_codequalifies as a workday.Parameter description:
calendar_code: The code for the public calendar, String type.
business_date: A String representing any business date, in the format
yyyyMMdd.
Return value description:
Confirms whether the
business_datein the public calendarcalendar_codeis a workday. It returnsTruefor a workday, otherwiseFalse.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
periodsday/month/year cycles closest tobusiness_datebeforebusiness_datein the public calendarcalendar_code.Parameter description:
calendar_code: The code for the public calendar, String type.
business_date: A String representing any business date, in the format
yyyyMMdd.periods: The number of cycles, Integer type, with a default of
1. Valid ranges are1d <= day_offset <= 7305d (20 years),1m <= day_offset <= 240m, or1y <= day_offset <= 20y.timeFormat: The 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
periodsday/month/year cycles closest tobusiness_datebeforebusiness_datein the public calendarcalendar_code. Ifbusiness_dateitself is a working day, thenbusiness_dateis considered 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); --Returns20231121,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:
Lists all workdays from the
startdateto theenddate(inclusive) within the public calendarcalendar_code.Parameter description:
calendar_code: The code representing the public calendar, String type.
startdate: A String representing any start business date, with the format
yyyyMMdd.enddate: Specifies any end business date as a String in the
yyyyMMddformat.ImportantThe valid range is
enddate - startdate <= 20 years.
Return value description:
Returns all workdays between
startdate(inclusive) andenddate(inclusive) in the public calendarcalendar_code. If thebusiness_dateitself is a workday, thenbusiness_dateis counted as 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 with the
label_codetag within theperiodsday/month/year cycles closest tobusiness_datebeforebusiness_datein the public calendarcalendar_code.Parameter description:
calendar_code: The code for the public calendar, String type.
label_code: The code for the label, String type.
business_date: Any business date, String type, in the format yyyyMMdd.
periods: The number of cycles, Integer type, with a default of
1. Valid ranges are1d <= day_offset <= 7305d (20 years),1m <= day_offset <= 240m, or1y <= day_offset <= 20y.timeFormat: The type of cycle, with a default of
d. Permitted types are:Day:
d.Month:
m.Year:
y.
Return value description:
Returns all working days with the
label_codetag within theperiodsday/month/year cycle closest tobusiness_datebeforebusiness_datein the public calendarcalendar_code. Ifbusiness_dateitself is a working day, thenbusiness_dateis considered 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 the number of workdays tagged with
calendar_codefromstartdatethroughenddate, inclusive, within the specified public calendarcalendar_code.Parameter description:
calendar_code: The identifier for the public calendar, String type.
label_code: The identifier for the label, String type.
startdate: Specify any start business date as a String in the
yyyyMMddformat.enddate: A String representing any end business date, in the format
yyyyMMdd.ImportantThe valid range is
enddate - startdate <= 20 years.
Return value description:
Returns all workdays with the label
lable_codebetweenstartdate(inclusive) andenddate(inclusive) in the public calendarcalendar_code. If thebusiness_dateitself is a workday, thenbusiness_dateis counted as 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