- 1 Minute to read
-
DarkLight
Dynamic Date Range
- 1 Minute to read
-
DarkLight
If the date range selection when creating source was not sufficient, you can define a dynamic date range relative to the current date.
When is Dynamic Range Needed?
In some cases, your date-related parameters have to be defined as part of the API call.
https://api.service.com/endpoint?startDate=2020-01-01&endDate=2020-12-31
If this call is automated, the extracted data will be from January 1, 2020 until December 31, 2020 every time. As such, both startDate and endDate parameters should be defined via a dynamic date range.
How Does it Work?
The URL of a source can look like this:
https://api.service.com/endpoint?startDate={{1m1}}&endDate={{1m1}}
The expression enclosed in double curly brackets {{1m1}} consists of three parts:
- The number at the start of expression 1m1. This represents the number of units (here months) to go back from the current date and defines the start of the range. 0 represents the current value.
- Unit definition: d = day (1d0), m = month (1m1), w = week (1w1)
- The last number sets the end of the range. 0 marks today, 1 marks yesterday, and so on. There is a rule that the first digit has to always be larger than the second one.
Examples
Expression
Expression |
Meaning |
{{0d0}} |
Today in ISO 8601 |
{{1d1}} |
Yesterday |
{{1d0}} |
Yesterday and today |
{{0m0}} |
This month |
{{1m1}} |
Last month |
{{90d1}} |
Ninety days ago until yesterday |
{{1w1}} |
Last week |
{{0w0}} |
This week starting from monday |
{{0y0}} |
This year |
{{1y1}} |
Last year |
{{1d1|U}} |
Yesterday in unix seconds |
API Call with 'yesterday' Date Range
https://api.service.com/endpoint?startDate={{1d1}}&endDate={{1d1}}
API Call with 'this month' Date Range
https://api.service.com/endpoint?startDate={{0m0}}&endDate={{0m0}}
Date String Formatting
Date string is by default written in the YYYY-MM-DD format (e.g. 2020-12-31). Unfortunately, not all APIs follow ISO 8601 standards. In such cases, it is possible to use date string formating.
Custom Formatting Examples
Expression |
Output |
{{0d0|Ymd}} |
20201231 |
{{0d0|Y-m-d\TH:i:s}} |
2020-12-31T00:00:00 |
Change Date Range in Manual Data Load
Dynamic date range is also used for manual data load when a calendar date range is not available. In this case, to manually load historical data, you will need to specify your date range in the source URL.