The Interval data type represents periods between dates or times, which can be precisely calculated and expressed through various units. Those can be combined and include additional options for different interval calculations.
In this doc, you’ll find more about the interval syntax, learn what are supported units and abbreviations, browse through examples and finally find out how to extract data from intervals.
The syntax for specifying an interval is as follows:
Parameters Description
Parameter | Description |
---|---|
quantity | The value representing the number of units |
unit | - Year, month, day, hour, minute, etc. - Abbreviations, short forms and dash format is supported - Plural forms are also acceptable (e.g. months, days, weeks) |
direction | An optional parameter: ago or empty string |
OPTION | Additional options when parsing interval |
Unit | Abbreviations |
---|---|
Millennium | - |
Century | - |
Decade | - |
Year | y , yr , yrs |
Month | - |
Week | - |
Day | d |
Hour | h , hr , hrs |
Minute | min , mins , m |
Second | s , sec , secs |
Millisecond | ms |
Microsecond | - |
YEAR
, MONTH
, DAY
, HOUR
, MINUTE
, SECOND
YEAR TO MONTH
, DAY TO HOUR
, DAY TO MINUTE
, DAY TO SECOND
, HOUR TO MINUTE
, HOUR TO SECOND
, MINUTE TO SECOND
In this example, we’ll calculate the interval by combining multiple units of time.
This example shows how to use abbreviated units for time intervals.
Here you’ll find out how to use the dash format for specifying intervals.
By running the code below, the output will show everything up to minutes and ignore seconds and miliseconds.
Executing the query below will result only years and months being displayed excluding days, hours, minutes, and seconds from the input.
In order to extract the interval numbers from the timestamp, you can use the EXTRACT() function the following way:
field
: supports time units, such as YEAR
, MONTH
, DAY
, HOUR
, etc.interval
: specified timestamp.As the output of the above query, only the minutes part will be returned.
0
as an output.The Interval data type represents periods between dates or times, which can be precisely calculated and expressed through various units. Those can be combined and include additional options for different interval calculations.
In this doc, you’ll find more about the interval syntax, learn what are supported units and abbreviations, browse through examples and finally find out how to extract data from intervals.
The syntax for specifying an interval is as follows:
Parameters Description
Parameter | Description |
---|---|
quantity | The value representing the number of units |
unit | - Year, month, day, hour, minute, etc. - Abbreviations, short forms and dash format is supported - Plural forms are also acceptable (e.g. months, days, weeks) |
direction | An optional parameter: ago or empty string |
OPTION | Additional options when parsing interval |
Unit | Abbreviations |
---|---|
Millennium | - |
Century | - |
Decade | - |
Year | y , yr , yrs |
Month | - |
Week | - |
Day | d |
Hour | h , hr , hrs |
Minute | min , mins , m |
Second | s , sec , secs |
Millisecond | ms |
Microsecond | - |
YEAR
, MONTH
, DAY
, HOUR
, MINUTE
, SECOND
YEAR TO MONTH
, DAY TO HOUR
, DAY TO MINUTE
, DAY TO SECOND
, HOUR TO MINUTE
, HOUR TO SECOND
, MINUTE TO SECOND
In this example, we’ll calculate the interval by combining multiple units of time.
This example shows how to use abbreviated units for time intervals.
Here you’ll find out how to use the dash format for specifying intervals.
By running the code below, the output will show everything up to minutes and ignore seconds and miliseconds.
Executing the query below will result only years and months being displayed excluding days, hours, minutes, and seconds from the input.
In order to extract the interval numbers from the timestamp, you can use the EXTRACT() function the following way:
field
: supports time units, such as YEAR
, MONTH
, DAY
, HOUR
, etc.interval
: specified timestamp.As the output of the above query, only the minutes part will be returned.
0
as an output.