← datediff operator page · time/datediff/comp_comp/manual_ex_1
pandas ✅ · DuckDB ✅
datediff(Id_2, Me_1) inside calc, from a date identifier to a time_period measure.
Days between two dates, Example 1, output verbatim: "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."
2020Q2 ends on 2020-06-30 and 2021Q1 on 2021-03-31, so Me_2 is 546, 639 and 90, Integers.
DS_r:= DS_1[calc Me_2 := datediff(Id_2, Me_1)];
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| G | 2019-01-01 | 2020Q2 |
| G | 2019-07-01 | 2021Q1 |
| T | 2020-12-31 | 2021Q1 |
{
"datasets": [
{
"name": "DS_1",
"DataStructure": [
{"name": "Id_1", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Id_2", "type": "Date", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Time_Period", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| G | 2019-01-01 | 2020Q2 | 546 |
| G | 2019-07-01 | 2021Q1 | 639 |
| T | 2020-12-31 | 2021Q1 | 90 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "String", "role": "Identifier"},
{"name": "Id_2", "type": "Date", "role": "Identifier"},
{"name": "Me_1", "type": "Time_Period", "role": "Measure"},
{"name": "Me_2", "type": "Integer", "role": "Measure"}
]
}
]
}