Datetime Functions
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.
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 indd.MM.yyyy
oryyyy-MM-dd
format, or one ofactualyear
,actulamonth
,actualquarter
,actualweek
,actualday
,now
n
represents the count of:d
days,w
weeks,m
months,q
quarters ory
year.
Examples:
'2011-01-01 + 1q - 2m + 1d' means Jan 1, 2011 + 1 quartal - two months + 1 day, that represents Feb 2, 2011 'actualYear + 1m + 1d' , (used on 8 Mar, 2011) means 1 Feb, 2011 + 1 month + 1 day, that represents 2 Feb, 2011 as well
Another way how to create the date strings is following:
date(day: dd, month: MM, year: YYYY) date(d: dd, m: MM, y: YYYY) date(week: w, year: YYYY) date(quarter: q, year: YYYY)
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 |
---|---|
| Changes the context of the evaluated expression to dateAt('2011-01-01', { i1 = M_NAME_1 i2 = M_NAME_2 if (i1 > i2) { return i1; } return i2; }); |
| Changes the date context of the expression and evaluates it aggregated in the specified interval dateInterval('2011-01-01', '2011-12-31' { i1 = M_NAME_1 i2 = M_NAME_2 if (i1 > i2) { return i1; } return i2; }); Values for the indicators |
| Changes the context of the evaluated expression to timeAt('13:33:23', { i1 = M_NAME_1 i2 = M_NAME_2 if (i1 > i2) { return i1; } return i2; }); |
| Changes the time context of the expression and evaluates it aggregated in the specified interval timeInterval('00:00:01', '23:59:59' { i1 = M_NAME_1 i2 = M_NAME_2 if (i1 > i2) { return i1; } return i2; }); Values for the indicators |
| Changes the context of the evaluated expression to |
| Changes the date context of the expression and evaluates it aggregated in the specified interval |
Object minus(String date, period, int) | Substracts the amount of specified minus(date(firstValue('L_DATE')), 'days', 20) //subtracts 20 days from the date value |
Object minus(String time, period, int) | Adds the amount of specified minus(time(firstValue('L_TIME')), 'minutes', 30) //subtracts 30 minutes from the time value |
Object plus(String date, period, int) | Adds the amount of specified plus(date(firstValue('L_DATE')), 'days', 20) //adds 20 days to the date value |
Object plus(String time, period, int) | Adds the amount of specified plus(time(firstValue('L_TIME')), 'seconds', 50) //adds 50 seconds to the time value |
| Changes the context of the evaluated expression to |
| Changes the time context of the expression and evaluates it aggregated in the specified interval |
| Evaluates the expression without date time interval. |
Obsolete functions
These functions may be removed in further releases
Function | Description |
---|---|
| Loads the indicator's value at specified date. |
| Loads the indicator's value at specified date aggregated for N previous levels. |
| Loads cumulative indicator's value for specified date interval. |
| Loads cumulative indicator's value for specified date interval aggregated for N previous levels. |
Advanced functions
Function | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| This function gradually adds the current value to the cumulated value. Example:
| ||||||||||||
| This function gradually adds the current value to the cumulated value. Example:
| ||||||||||||
| Value of the passed indicator calculated for previous date or time value (e.g. previous month, day, hour, ...). Example:
| ||||||||||||
| Value of the passed indicator calculated for previous date or time value (e.g. previous month, day, hour, ...). Parameter | ||||||||||||
| Value of the passed indicator calculated for next date or time value (e.g. previous month, day, hour, ...). Example:
| ||||||||||||
| Value of the passed indicator calculated for next date or time value (e.g. previous month, day, hour, ...). Parameter | ||||||||||||
| 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: daysBetween(date(firstValue('L_DATE_FROM'),date(firstValue('L_DATE_TO'), 6,7) | ||||||||||||
| Function calculates number of days between provided dates. | ||||||||||||
| Function calculates number of months between provided dates. | ||||||||||||
| Function calculates number of months between provided dates. | ||||||||||||
| Function calculates number of years between provided dates. | ||||||||||||
| Function calculates number of years between provided dates. |
For changing the whole context of the evaluated expression, you can use following functions:
| Changes the context of the expression to desired previous date period. The value of the
| ||||||||||||
| Changes the context of the expression to desired next date period. The value of the |
The following example works with values, which are loaded for one year before the actual table/chart datetime entry:
return prev(YEAR) { M_NAME_1 / M_NAME_2 * 100 }
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:
dateAt ('2010-12-08') { timeAt('09:04:02') { M_INDICATOR } }