Public calendar built-in functions
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 |
Calculates the nearest | |
Calculates the nearest | |
Calculates whether the | |
Calculates whether the | |
Calculate all working days within the | |
Calculates and returns all workdays between | |
Calculate all working days that contain the | |
Calculates all workdays containing the |
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 givenday_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 tobusiness_datebeforebusiness_datein the public calendarcalendar_code. Ifbusiness_dateitself is a business day, thenbusiness_dateis 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_datethat includes thelabel_code, offset byday_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 from1 <= day_offset <= 7305 (20 years), with a default of 1.
Return Value Description:
Returns the date in the public calendar
calendar_codethat is the closest tobusiness_datebeforebusiness_date, which is theday_offsetth date containing the taglabel_code. Ifbusiness_dateitself contains the taglabel_code, thenbusiness_dateis considered the first date. The return type is String, formatted asyyyyMMdd.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_datewithin the public calendarcalendar_codeis tagged withlabel_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_dateincludes thelabel_codetag within thecalendar_code. ReturnsTrueif the tag 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_datewithin the public calendarcalendar_codeis 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_dateis a workday within thecalendar_code. ReturnsTruefor a workday, otherwiseFalsefor 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
periodsday/month/year cycles closest to thebusiness_datebefore thebusiness_datein the public calendarcalendar_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, or1y <= day_offset <= 20y, with a default of1.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
periodsday/month/year cycles closest tobusiness_datebeforebusiness_datein the public calendarcalendar_code. Ifbusiness_dateitself is a working day,business_dateis 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) andenddate(inclusive) within thecalendar_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.ImportantThe range between enddate and
startdatemust not exceed 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 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_codetag within theperiodsday/month/year cycles closest to thebusiness_datebefore thebusiness_datein the public calendarcalendar_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, or1y <= day_offset <= 20y, with a default of1.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_codetag within theperiodsday/month/year cycles closest to thebusiness_datein the public calendarcalendar_codebefore thebusiness_date. If thebusiness_dateitself is a working day, thenbusiness_dateis 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_codetag that fall betweenstartdateandenddate, inclusive, within the specified public calendarcalendar_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.ImportantThe range between enddate and
startdatemust not exceed 20 years.
Return Value Description:
Returns all workdays containing the
label_codetag betweenstartdate(inclusive) andenddate(inclusive) in the public calendarcalendar_code. If thebusiness_dateitself is a workday, thenbusiness_dateis 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