All Products
Search
Document Center

Dataphin:Appendix: Statistical period expression parameters

Last Updated:Jan 21, 2025

Function list

lastNDate

  • Usage: Determines the start date of the period for the last N days.

  • Parameters:

    • (Required) currentDate: The current date in the format yyyyMMdd.

    • (Required) preDays: The number of days to look back, specified as an integer.

    • (Required) format: The date format, which is yyyyMMdd.

  • Return value:

    • The start date of the last N days period, returned as a string in the format yyyyMMdd.

  • Example:

    • lastNDate('20180118', 7,'yyyyMMdd') yields 20180112.

cBeginDate

  • Usage: Retrieves the start date of the natural period N periods prior.

  • Parameters:

    • (Required) currentDate: The current date as a string in the format yyyyMMdd.

    • (Required) timeFormat: The type of natural period, with the following options:

      • w: Calendar week.

      • m: Calendar month.

      • q: Calendar quarter.

      • y: Calendar year.

    • (Optional) length: The number of natural periods to count back. If not provided, the default is 1.

    • (Required) format: The date format, which is yyyyMMdd.

  • Return value:

    • The start date of the natural period N periods ago, returned as a string in the format yyyyMMdd.

  • Example:

    • cBeginDate('20180118', 'm','yyyyMMdd') yields 20171201.

    • cBeginDate('20180118', 'w','yyyyMMdd') yields 20180108.

    • cBeginDate('20180118', 'w', 2,'yyyyMMdd') yields 20180101.

cEndDate

  • Usage: Determines the end date of the previous natural period.

  • Parameters:

    • (Required) currentDate: The current date as a string in the format yyyyMMdd.

    • (Required) timeFormat: The type of natural period, with the following options:

      • w: Calendar week.

      • m: Calendar month.

      • q: Calendar quarter.

      • y: Calendar year.

    • (Required) format: The date format, which is yyyyMMdd.

  • Return value:

    • The end date of the previous natural period, returned as a string in the format yyyyMMdd.

  • Example:

    • cEndDate('20180118', 'm','yyyyMMdd') yields 20171231.

    • cEndDate('20180118', 'w','yyyyMMdd') yields 20180114.

    • cEndDate('20180118', 'y','yyyyMMdd') yields 20171231.

tdBeginDate

  • Usage: Retrieves the start date of the natural period N periods prior. Unlike cBeginDate, if the length is not provided, it defaults to the start of the current period. This function is ideal for calculating "up to today" type indicators.

  • Parameters:

    • (Required) currentDate: The current date as a string in the format yyyyMMdd.

    • (Optional) timeFormat: The type of natural period. If not provided, the default is 19700101. The allowed types are:

      • w: Calendar week.

      • m: Calendar month.

      • q: Calendar quarter.

      • y: Calendar year.

    • (Optional) length: The number of natural periods to count back. If not provided, the default is 0.

    • (Required) format: The date format, which is yyyyMMdd.

  • Return value:

    • The start date of the natural period N periods prior, returned as a string in the format yyyyMMdd.

  • Example:

    • tdBeginDate('20180118','yyyyMMdd') yields 19700101.

    • tdBeginDate('20180118', 'm','yyyyMMdd') yields 20180101.

    • tdBeginDate('20180118', 'w','yyyyMMdd') yields 20180115.

    • tdBeginDate('20180118', 'w', 2,'yyyyMMdd') yields 20180101.

CustomBeginDate

  • Usage: Retrieves the start date of the custom period N periods prior, considering the current date as part of the first custom period. This function is suitable for calculating statistical periods that adhere to changing periods, period rules, or sliding yet fixed time intervals, such as fiscal months and fiscal years. It is often used in conjunction with CustomEndDate.

  • Parameters:

    • (Required) currentDate: The current date as a string in the format yyyyMMdd.

    • (Required) timeFormat: The type of natural period, with the following options:

      • m: Calendar month.

      • q: Calendar quarter.

      • y: Calendar year.

    • (Required) customShift: The start date of the custom period, specified as a string. For year and quarter, the format is MMdd; for month, the default format is dd.

      Note

      Note: dd values only support numbers 01~28.

    • (Optional) length: The number of custom periods to count back. If not provided, the default is 1. If 0, it returns the start of the current period.

    • (Required) format: The date format, which is yyyyMMdd.

  • Return value:

    • The start date of the custom period N periods prior, returned as a string in the format yyyyMMdd.

  • Example:

    • CustomBeginDate('20190802', 'y', '0401','yyyyMMdd') yields ```html 20180401.

    • CustomBeginDate('20190802', 'y', '0401', 0,'yyyyMMdd') yields 20190401.

    • CustomBeginDate('20190802', 'q', '0101','yyyyMMdd') yields 20190401.

    • CustomBeginDate('20190802', 'm', '15','yyyyMMdd') yields 20190615.

    • CustomBeginDate('20190802', 'm', '15', 2,'yyyyMMdd') yields 20190515.

CustomEndDate

  • Usage: Retrieves the end date of the custom period N periods prior, considering the current date as part of the first custom period. This function is suitable for calculating statistical periods that adhere to changing periods, period rules, or sliding yet fixed time intervals, such as fiscal months and fiscal years. It is often used in conjunction with CustomBeginDate.

  • Parameters:

    • (Required) currentDate: The current date as a string in the format yyyyMMdd.

    • (Required) timeFormat: The type of natural period, with the following options:

      • m: Calendar month.

      • q: Calendar quarter.

      • y: Calendar year.

    • (Required) customShift: The start date of the custom period, specified as a string. For year and quarter, the format is MMdd; for month, the default format is dd.

      Note

      Note: dd values only support numbers 01~28.

    • (Optional) length: The number of custom periods to count back. If not provided, the default is 1.

    • (Required) format: The date format, which is yyyyMMdd.

  • Return value:

    • The end date of the custom period N periods prior, returned as a string in the format yyyyMMdd.

  • Example:

    • CustomEndDate('20190802', 'y', '0401','yyyyMMdd') yields 20190331.

    • CustomEndDate('20190802', 'q', '0101','yyyyMMdd') yields 20190630.

    • CustomEndDate('20190802', 'm', '15','yyyyMMdd') yields 20190714.

    • CustomEndDate('20190802', 'm', '15', 2,'yyyyMMdd') yields 20190614.

substring

  • Usage: Returns a substring starting from the specified start position to the end of the string. Positions begin at 1. If the start is negative, it counts backwards from the end of the string.

  • Parameters:

    • (Required) currentDate: The current date as a string in the format yyyyMMdd.

    • (Required) start: The start position for the substring.

    • (Required) len: The length of the substring to extract.

  • Return value:

    • Returns the substring of the specified length starting at the given start position from the string.

  • Example:

    • substring('20190802',1,4) yields 2019.

    • substring('20190802',1,6) yields 201908.

lastNHour

  • Usage: Determines the start hour of the last N hours period.

  • Parameters:

    • (Required) currentDatetime: The business time as a string in the format yyyyMMddHH0000.

    • (Required) preHours: The number of hours to look back, specified as an integer.

  • Return value:

    • The start hour of the last N hours period, returned as a string in the format yyyyMMddHH0000.

  • Example:

    • lastNHour('20180118160000', 7) yields 20180118100000.

dthBeginDatetime

  • Usage: Retrieves the zero hour of the date where the business time is located.

  • Parameters:

    • (Required) currentDatetime: The business time as a string in the format yyyyMMddHH0000.

  • Return value:

    • The zero hour of the date where the business time is located, returned as a string in the format yyyyMMdd000000.

  • Example:

    • dthBeginDatetime('20180118160000') yields 20180118000000.

lastNMinute

  • Usage: Determines the start minute of the last N minutes period.

  • Parameters:

    • (Required) currentDatetime: The business time as a string in the format yyyyMMddHHmm00.

    • (Required) preMinutes: The number of minutes to look back, specified as an integer.

  • Return value:

    • The start minute of the last N minutes period, returned as a string in the format yyyyMMddHHmm00.

  • Example:

    • lastNMinutes('20180118164500', 45) yields 20180118160000.

dtmiBeginDatetime

  • Usage: Retrieves the zero hour of the date where the business time is located.

  • Parameters:

    • (Required) currentDatetime: The business time as a string, in the format yyyyMMddHH0000.

    • (Optional) timeFormat: The type of natural period, with the following option:

      • h: Hour.

  • Return value:

    • If the timeFormat parameter is h, it returns the zero hour of the hour where the business time is located, in the format yyyyMMddHH0000.

    • If the timeFormat parameter is not provided, it returns the zero hour of the date where the business time is located, in the format yyyyMMdd000000.

  • Example:

    • dtmiBeginDatetime('20180118160000') yields 20180118000000.

    • dtmiBeginDatetime('20180118164500', 'h') yields 20180118160000.

Scenarios

Function

Development/Modeling

Quality/Partition filter expression

lastNDate

Supported

Supported

cBeginDate

Supported

Supported

cEndDate

Supported

Supported

tdBeginDate

Supported

Supported

CustomBeginDate

Supported

Supported

CustomEndDate

Supported

Supported

substring

Supported

Not applicable

lastNHour

Supported

Not applicable

dthBeginDatetime

Supported

Not applicable

lastNMinute

Supported

Not applicable

dtmiBeginDatetime

Supported

Not applicable

Application instances

Statistical period

Start time expression

End time expression

Last day

${bizdate}

${bizdate}

Last N days

lastNDate('${bizdate}', N)

${bizdate}

Last M to N days

lastNDate('${bizdate}', M)

lastNDate('${bizdate}', N)

Historical up to today

tdBeginDate('${bizdate}')

${bizdate}

Calendar week

cBeginDate('${bizdate}', 'w')

cEndDate('${bizdate}', 'w')

Calendar month

cBeginDate('${bizdate}', 'm')

cEndDate('${bizdate}', 'm')

Calendar quarter

cBeginDate('${bizdate}', 'q')

cEndDate('${bizdate}', 'q')

Calendar year

cBeginDate('${bizdate}', 'y')

cEndDate('${bizdate}', 'y')

Last 2 calendar months

cBeginDate('${bizdate}', 'm', 2)

cEndDate('${bizdate}', 'm')

Calendar week up to today

tdBeginDate('${bizdate}', 'w')

${bizdate}

Calendar month up to today

tdBeginDate('${bizdate}', 'm')

${bizdate}

Calendar quarter up to today

tdBeginDate('${bizdate}', 'q')

${bizdate}

Calendar year up to today

tdBeginDate('${bizdate}', 'y')

${bizdate}

Last calendar month up to today

tdBeginDate('${bizdate}', 'm', 1)

${bizdate}

Fiscal year

CustomBeginDate('${bizdate}', 'y', '0401')

CustomEndDate('${bizdate}', 'y', '0401')