Natural Time Expression
This documentation assumes you are familiar with the following concepts:
Introduction
Using the matches filter operator and our natural time expressions, you can construct flexible time filtering conditions for your report. We categorize the time expressions by their functionality:
- Select exactly one time unit: The expression helps users selecting one particular time unit, like a certain year, day, or hour.
- Select a time span: The expression helps users selecting more than one time unit (like 2 years, 3 days, 4 hours), or a range from one to another time point.
The time units we currently support are: year(s)
, quarter(s)
, months(s)
, week(s)
, day(s)
, hour(s)
, minute(s)
, second(s)
Select exactly one time unit
Absolute time expressions
Pattern | Example | Time covered | Notes |
---|---|---|---|
YYYY | 2024 | All time in the year 2024 | |
MMM YYYY , MMMM YYYY | Apr 2024 , April 2024 | All time in April of 2024 | |
DD MMM YYYY , MMM DD YYYY | 30 April 2024 , April 30 2024 | 2024-04-30 | |
DD-MM-YYYY , YYYY-MM-DD | 30-04-2024 , 2024-04-30 | 2024-04-30 | |
DD/MM/YYYY , YYYY/MM/DD | 30/04/2024 , 2024/04/30 | 2024-04-30 | |
HH HH:MM HH:MM:SS | 15 15:00 15:00:30 | From the beginning the time expression to just before the next smallest unit of the expression starts.15:00 covers 60 seconds from 15:00:00 to just before the next minute (15:01:00) starts, because minute is the smallest unit mentioned. | Without a [date] part, the time is interpreted as of the current date. |
[date] [time] | 2024-04-30 15 2024-04-30 15:00 2024-04-30 15:00:30 | The time period of the mentioned date | Only accepted [date] formats: DD-MM-YYYY, YYYY-MM-DD, DD/MM/YYYY, YYYY/MM/DD. |
Relative time expressions
Relative time expression's resolution to an exact time will depend on the current time.
Pattern | Example | Time covered | Notes |
---|---|---|---|
beginning | 1970-01-01 | ||
today | Today is 2024-04-01, and we use today | 2024-04-01 | |
yesterday | Today is 2024-04-01, and we use yesterday | 2024-03-31 | |
tomorrow | Today is 2024-04-01, and we use tomorrow | 2024-04-02 | |
now | Today is 2024-04-01, the current time is 15:00:30, and we use now | 2024-04-01 15:00:30 | |
this [time unit] | Today is 2024-04-15, and we use this month | All time within Apr 2024 | Cover all time within the same [time unit] with the current moment. |
The current time is 2024-04-15 15:30:00, and we use this hour | All time within 2024-04-15, 15pm | ||
[weekday] this week | Today is Thursday 2024-04-18, and we use monday this week or mon this week | 2024-04-15 | |
[weekday] last x week(s) | Today is Thursday 2024-04-18, and we use monday last 1 week | 2024-04-08 | last/next keywords behave the same as the last/next operators |
[weekday] next x week(s) | Today is Thursday 2024-04-18, and we use monday next 1 week | 2024-04-22 | |
[time period] begin | Today is 2024-04-15, and we use this month begin | 2024-04-01 | [time period] = this/next/last + [quantity] + [time unit]. Examples of [time period]: this year , this month , last 2 weeks , this hour , next 10 minutes ... |
The current time is 2024-01-01 15:30, and we use this hour begin | One second from 2024-01-01 15:00:00 to before 2024-01-01 15:00:01 starts | ||
[time period] end | Today is 2024-04-15, and we use this month end | 2024-04-30 | |
The current time is 2024-01-01 15:30, and we use this hour end | One second from 2024-01-01 15:59:59 to before 2024-01-01 16:00:00 starts | ||
x [time unit] ago | Today is 2024-04-15, and we use 5 days ago | 2024-04-10 | Cover a time unit that happened x complete time units before now. |
The current time is 2024-04-15 15:30:00, and we use 5 hours ago | All time within 2024-04-15, 10am to 11am | ||
x [time unit] from now | Today is 2024-04-15, and we use 2 days from now | 2024-04-17 | Cover a time unit that happened x complete time units from now. |
The current time is 2024-04-15 15:30:00, and we use 5 hours from now | All time within 2024-04-15, 20pm to 21pm |
begin
and end
begin
and end
keywords are used to return the first and last unit of a time range. They can be used in combination with time span expressions to create very flexible exact-unit selection.
These exact-unit selection can also be used as the start and end for even more flexible time span selection.
Examples
- Year: 2024
- Month: Apr 2024 / April 2024
- Date: 30 April 2024, 2024-04-30
- Relative dates:
- today, tomorrow, yesterday, this day
- Monday this week, Monday last 2 weeks, Tuesday next week, Tuesday next 2 weeks
- this month begin, this month end; this week begin, this week end
- 3 days ago / last 3 days begin
- next 2 day end: returns the date of two complete days from the current date
- Date time: 2024-04-30 15:30:00
- Relative time:
- now
- 1 hours ago, 20 minutes ago, 30 seconds ago
- 1 hour from now, 20 minutes from now, 30 seconds from now
Select a time span
These expressions help users to select a time range between two points, or select a span of N time units.
Pattern | Example | Time covered | Notes |
---|---|---|---|
[start] -/to [end] | Today is 2024-04-15, and we use 2024-04-15 - this month end or today to this month end | All dates from 2024-04-15 to 2024-04-30 | Cover all time between two points including the end point.[start] and [end] can be any exact-unit expression. Their time granularity can be different. |
Current time is 2024-01-01 15:35:00, and we use last 3 hours to this minute | All time from 2024-01-01 12:00:00 to (and including) 2024-01-01 15:35 | ||
[start] till/until [end] | Today is 2024-04-15, and we use today till this month end | All dates from 2024-04-15 to 2024-04-29 | Cover all time between two points, excluding the end point.[start] and [end] can be any exact-unit expression. Their time granularity can be different. |
Current time is 2024-01-01 15:35:00, and we use last 3 hours to this minute | All time from 2024-01-01 12:00:00 to before 2024-01-01 15:35:00 starts | ||
last x [time unit] | Today is 2024-04-15, and we use last 2 months | All dates in Feb 2024 and Mar 2024, since Apr 2024 is incomplete | Cover all time in the previous x complete units. |
Current time is 2024-01-01 15:35, and we use last 3 hours | All time from 2024-01-01 12:00 to (and including) 2024-01-01 14pm | ||
next x [time unit] | Today is 2024-04-15, and we use next 2 months | All dates in May 2024 and Jun 2024, since Apr 2024 is incomplete | Cover all dates in the next x complete units. |
Current time is 2024-01-01 15:35, and we use next 3 hours | All time from 2024-01-01 16:00 to (and including) 2024-01-01 18pm |
Examples
[start] and [end] in the same unit:
- April 15 2024 to may 15 2024, 2024-04-15 to 2024-05-15
- April 15 2024 until may 16 2024, 2024-04-15 till 2024-05-16
- 30 april 2024 12:00 till 30 april 2024 14:00
- last 3 days, next 3 weeks
- last 10 hours, next 30 minutes
[start] and [end] in different units:
- 2023 to september 2024
- 2 months ago to monday last week
- this year begin to this week end
- yesterday to now
- this weekend to next 2 months
Caching implications
When using relative time expressions, your SQL will be dynamically generated according to the current time.
Therefore, relative time expressions can affect how Holistics caches your SQL results.
For example, let's say we have this filter that uses now
When we open the report (containing the above filter) at 2024-09-17 01:09:38.000 -07:00
, the report generates a SQL with this WHERE clause:
WHERE
(CAST ( "order_master"."order_created_at" AS timestamptz )
>= CAST ( '2024-09-14T00:00:00.000-07:00' AS timestamptz ))
AND
(CAST ( "order_master"."order_created_at" AS timestamptz )
< CAST ( '2024-09-17T01:09:38.000-07:00' AS timestamptz ))
Then when we open the report at 2024-09-17 01:17:33.000 -07:00
, the report generates another SQL with this WHERE clause:
WHERE
(CAST ( "order_master"."order_created_at" AS timestamptz )
>= CAST ( '2024-09-14T00:00:00.000-07:00' AS timestamptz ))
AND
(CAST ( "order_master"."order_created_at" AS timestamptz )
< CAST ( '2024-09-17T01:17:33.000-07:00' AS timestamptz ))
Because the above 2 SQLs are different, Holistics will not re-use cache in the latter run, regardless of the report's cache settings.
If we used today
instead of now
:
The report would generate this same SQL when we visit it at both 2024-09-17 01:09:38.000 -07:00
and 2024-09-17 01:17:33.000 -07:00
:
WHERE
(CAST ( "order_master"."order_created_at" AS timestamptz )
>= CAST ( '2024-09-14T00:00:00.000-07:00' AS timestamptz ))
AND
(CAST ( "order_master"."order_created_at" AS timestamptz )
< CAST ( '2024-09-18T00:00:00.000-07:00' AS timestamptz ))
And Holistics would be able to re-use cache in both runs.
Be mindful of the caching implications when using Natural Time Expression.
Only use high-freshness values like now
when you really need high freshness.
Otherwise, you can choose lower-freshness values like today
, this hour
, last hour
, etc.
Learn more about Holistics Report Caching here.