Datetime Functions

    Icon

    For the purpose of this reference guide: Date refers only to year, months, days (and quarters, weeks) and their combinations. Time refers to hours, minutes and seconds and their combinations. For combination of date and time we strictly use datetime term.

    Icon

    See the Date and time functions inherited from transformation scripting.

    Date strings

    The date string parameters are entered absolutely (dd.MM.yyyy, yyyy-MM-dd or according to domain settings) or relatively (time variables) by operators:

    date +|- n[d|w|m|q|y]

    where

    • date is date in dd.MM.yyyy or yyyy-MM-dd format, or one of actualyear, actulamonth, actualquarter, actualweek, actualday, now
    • n represents the count of:
    • d days, w weeks, m months, q quarters or y year.

    Examples:

    Another way how to create the date strings is following:

    Changing datetime context

    What is the datetime context? Consider following example:

     

    01/2011

    02/2011

    03/2011

    formula indicator

    1000

    1200

    1300

    Formula is evaluated for each column - in this example, in columns are values evaluated for particular months. During the evaluation of value 1000, the datetime context was 01/2011, then during the processing of value 1200, the context was 02/2011 etc.

    Function

    Description

    Object dateAt(String dateString, { expression })

    Changes the context of the evaluated expression to dateString date. Example:

    Object dateInterval(String from, String to, { expression })

    Changes the date context of the expression and evaluates it aggregated in the specified interval from - to. Example:

    Values for the indicators M_NAME_1 and M_NAME_2 are aggregated for the whole period.

    Object timeAt(String timeString, { expression })

    Changes the context of the evaluated expression to timeString date. Example:

    Object timeInterval(String from, String to, { expression })

    Changes the time context of the expression and evaluates it aggregated in the specified interval from - to. Example:

    Values for the indicators M_NAME_1 and M_NAME_2 are aggregated for the whole period.

    Object dateAt (String date, String period) { expression })

    Changes the context of the evaluated expression to dateString date - aggregated by the defined period {DAY, D, WEEK, W, MONTH, M, YEAR, Y}.

    Object dateInterval (String from, String to, String period ) { expression })

    Changes the date context of the expression and evaluates it aggregated in the specified interval from - to. Aggregation by the defined period {DAY, D, WEEK, W, MONTH, M, YEAR, Y} is also performed.

    Object minus(String date, period, int)

    Substracts the amount of specified period (years, months, weeks, days) to the defined date value.


    Object minus(String time, period, int)

    Adds the amount of specified period (years, months, weeks, days) to the defined date value.

    Object plus(String date, period, int)

    Adds the amount of specified period (years, months, weeks, days) to the defined date value.


    Object plus(String time, period, int)

    Adds the amount of specified period (hours, minutes, seconds) to the defined date value.

    Object timeAt (String time, String period) { expression })

    Changes the context of the evaluated expression to timeString time - aggregated by the defined period {HOUR, H, MINUTE, SECOND}.

    Object timeInterval (String from, String to, period) { expression })

    Changes the time context of the expression and evaluates it aggregated in the specified interval from - to. Aggregation by the defined period {HOUR, H, MINUTE, SECOND} is also performed.

    Object withoutDateTime() { expression })

    Evaluates the expression without date time interval.

    Obsolete functions

    Icon

    These functions may be removed in further releases

    Function

    Description

    Object value(String dateString, String indicator)

    Loads the indicator's value at specified date.

    Object value(String dateString, int drill_down_level)

    Loads the indicator's value at specified date aggregated for N previous levels.

    Object value(String dateFrom, String dateTo, String indicator)

    Loads cumulative indicator's value for specified date interval.

    Object value(String dateFrom, String dateTo, String indicator, int dril_down_level)

    Loads cumulative indicator's value for specified date interval aggregated for N previous levels.

    Advanced functions

     

    Function

    Description

    Number cumulateFromDate(String startDate, String indicator)

    This function gradually adds the current value to the cumulated value. Example:

     

    01/2011

    02/2011

    03/2011

    M_NAME_1

    1000

    1200

    1300

    cumulateFromDate('2011-01-01', 'M_NAME_1')

    1000

    2200

    3500

    Number cumulateFromTime(String startTime, String indicator)

    This function gradually adds the current value to the cumulated value. Example:

     

    00:01

    00:02

    00:03

    M_NAME_1

    1000

    1200

    1300

    cumulateFromTime('00:01', 'M_NAME_1')

    1000

    2200

    3500

    prev(String indicatorCode)

    Value of the passed indicator calculated for previous date or time value (e.g. previous month, day, hour, ...). Example:

     

    01/2011

    02/2011

    03/2011

    M_NAME_1

    1000

    1200

    1300

    prev('M_NAME_1')

     

    1000

    1200

    Number prev(String indicatorCode, int prevLevelAgg)

    Value of the passed indicator calculated for previous date or time value (e.g. previous month, day, hour, ...). Parameter prevLevelAgg represents number of previous levels which should be aggregated.

    Number next(String indicatorCode)

    Value of the passed indicator calculated for next date or time value (e.g. previous month, day, hour, ...). Example:

     

    01/2011

    02/2011

    03/2011

    M_NAME_1

    1000

    1200

    1300

    next('M_NAME_1')

    1200

    1300

     

    Number next(String indicatorCode, int prevLevelAgg)

    Value of the passed indicator calculated for next date or time value (e.g. previous month, day, hour, ...). Parameter prevLevelAgg represents number of previous levels which should be aggregated.

    int daysBetween(DateTime dateFrom, DateTime dateTo)

    Function calculates number of days between provided dates.

    int daysBetween(DateTime dateFrom, DateTime dateTo, int[])

    Function calculates number of days between provided dates and excludes selected day(s) of the week. Day of the week is referenced by number: 1 is Monday, 7 is Sunday.


    Following example shows, how Saturdays and Sundays can be excluded from the calculation:


    int daysBetween(LocalDate dateFrom, LocalDate dateTo)

    Function calculates number of days between provided dates.

    int monthsBetween(DateTime dateFrom, DateTime dateTo)

    Function calculates number of months between provided dates.

    int monthsBetween(LocalDate dateFrom, LocalDate dateTo)

    Function calculates number of months between provided dates.

    int yearsBetween(DateTime dateFrom, DateTime dateTo)

    Function calculates number of years between provided dates.

    int yearsBetween(LocalDate dateFrom, LocalDate dateTo)

    Function calculates number of years between provided dates.

    For changing the whole context of the evaluated expression, you can use following functions:

    Number prev(String period, { expression })

    Changes the context of the expression to desired previous date period. The value of the period parameter is one of: DAY, WEEK, MONTH, QUARTER, YEAR. Example:

     

    01/2011

    02/2011

    03/2011

    M_NAME_1

    1000

    1200

    1300

    prev(MONTH) { M_NAME_1 } 

     

    1000

    1200

    Number next(String period, { expression })

    Changes the context of the expression to desired next date period. The value of the period parameter is one of: DAY, WEEK, MONTH, QUARTER, YEAR

    The following example works with values, which are loaded for one year before the actual table/chart datetime entry:

    Icon

    You may simply enter only the first letter of time unit (in case of time context changing formulas) instead of their full names (Y,Q,M,W,D), for example prev(Y){}

    Nested expressions

    Date and time functions can be combined (if applicable), eg.: Value of M_INDICATOR at 8th December 2010, 9:04:02AM:

    Next Steps