Days between two dates: datediff
Syntax
datediff ( dateFrom , dateTo )
Input parameters
dateFrom |
the starting date/time period |
dateTo |
the ending date/time period |
Examples of valid syntaxes
datediff (2022Q1, 2023Q2)
datediff (2020-12-14,2021-04-20)
datediff (2021Q2, 2021-11-04)
ds2 := ds1[calc Me3 := datediff(Me1, Me2)]
Semantics for scalar operations
The operator datediff returns the number of days between two dates or time periods. The last day of the time period is assumed as the starting/ending date.
Input parameters type
dateFrom, dateTo:
component<time>
| time
Result type
result
component<integer>
| integer
Additional Constraints
None.
Behaviour
The scalar version of this operator takes as input two date or time_period values and returns a scalar integer value.
In the component version, that can be used in a calc clause, a new component of type integer is added to the dataset.
Examples
Given the dataset DS_1:
Input DS_1 (see structure)
Id_1 |
Id_2 |
Me_1 |
---|---|---|
G |
2019-01-01 |
2020Q2 |
G |
2019-07-01 |
2021Q1 |
T |
2020-12-31 |
2021Q1 |
Example 1
DS_r:= DS_1[calc Me2 := datediff(Id_2, Me_1)];
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
Me_2 |
---|---|---|---|
G |
2019-01-01 |
2020Q2 |
546 |
G |
2019-07-01 |
2021Q1 |
273 |
T |
2020-12-31 |
2021Q1 |
90 |
Example 2
dayofyear (2020-04-07);
returns 98.