Dynamic Date Range
  • 1 Minute to read
  • Dark
    Light

Dynamic Date Range

  • Dark
    Light

Dataddo is able to define a dynamic date range relative to the current date.

When is The Dynamic Range Needed?

Imagine a situation where date-related params must be defined as part of the API call.

https://api.service.com/endpoint?startDate=2019-07-01&endDate=2019-07-31

If such a call is automated, the extracted dataset will always be the same, which is presumably not ideal. Both startDate and endDate params should be dynamically generated. This can be done using dynamic date range expressions such as follows.

How Does it Work?

https://api.service.com/endpoint?startDate={{1m1}}&endDate={{1m1}}

The expression is enclosed in double curly brackets consists of three parts:

  1. The number at the start of expression 1m1. This represents the number of units (on this occasion, months) to go back from the current date and defines the start of the range. 0 represents the current value.

  2. Unit definition: d = day, m = month, w = week

  3. 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 notation (2022-12-31)

{{1d1}}

Yesterday

{{1d0}}

Yeasterday and today

{{0m0}}

This month

{{1m1}}

Last month

{{90d1}}

Ninety days ago till 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

The date string is by default output as YYYY-MM-DD string (e.g. 2019-12-31). Unfortunately, not all APIs follow ISO 8601 standards. In such cases, it is possible to use a date string formating.

Custom Formatting Examples

Expression

Output

{{0d0|Ymd}}

20201231

{{0d0|Y-m-d\TH:i:s}}

2020-12-31T00:00:00

How to Change Date Range in Ad-hoc Data Load

Another case is that selecting date range in the Ad-hoc data load panel is not possible. When this occurs, there is still a way to get your historical data. This process is a bit more advanced but feasible following this guide.


Was this article helpful?

What's Next