Days between two dates · datediff
---
config:
flowchart:
useMaxWidth: false
---
flowchart TB
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Days between two dates · datediff<br/>🟢4"]:::ok
subgraph G_comp["Component"]
direction LR
v_comp_comp["calc datediff(comp, comp)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc_date["datediff(date, date)"]:::ok
v_sc_time_period["datediff(time_period, time_period)"]:::ok
v_sc_mixed["datediff(time_period, date)"]:::ok
end
O --- G_comp
O --- G_sc
style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
click v_comp_comp href "#form-comp-comp"
click v_sc_date href "#form-sc-date"
click v_sc_time_period href "#form-sc-time-period"
click v_sc_mixed href "#form-sc-mixed"
Types
Takes date, time_period · Gives integer
Comes from · date, time_period — 8 operators in 2 blocks 🟢8
General purpose operators (1) 🟢1
Comes from · operators that return any type (their input's) — 36 operators in 8 blocks 🟢36
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Goes to · integer — 44 operators in 8 blocks 🟢44
General purpose operators (1) 🟢1
String operators (2) 🟢2
Numeric operators (18) 🟢18
Time operators (6) 🟢6
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (10) 🟢10
Data validation operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 46 operators in 8 blocks 🟢46
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (8) 🟢8
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Forms
calc datediff(comp, comp) 🟢 · date, time_period → integer
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
datediff(Id_2, Me_1)insidecalc, from a date identifier to a time_period measure.- Manual:
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.”
- Expected:
2020Q2ends on 2020-06-30 and2021Q1on 2021-03-31, soMe_2is 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 |
| 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 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
datediff(date, date) 🟢 · date → integer
Across the new year 🟢 pandas ✅ · DuckDB ✅
- Tests:
datediff(SC_1, SC_2)of two scalar dates,SC_1= 2020-12-14 andSC_2= 2021-04-20, the page’s valid syntaxdatediff (2020-12-14,2021-04-20), with the dates given in the defaultYYYY-MM-DDform, as VTL has no date literal.- Manual:
Days between two dates: “The operator datediff returns the number of days between two dates or time periods.”
- Expected:
DS_r = 127, an Integer: 17 days to the end of 2020, then 31, 28 (2021 is not a leap year), 31 and 20.
DS_r := datediff(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 2020-12-14 | 2021-04-20 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
datediff(time_period, time_period) 🟢 · time_period → integer
Last days of two quarters 🟢 pandas ✅ · DuckDB ✅
- Tests:
datediff(SC_1, SC_2)of two scalar time periods,SC_1= 2022Q1 andSC_2= 2023Q2, the page’s valid syntaxdatediff (2022Q1, 2023Q2).- Manual:
Days between two dates: “The last day of the time period is assumed as the starting/ending date.”
- Expected:
DS_r = 456, an Integer: from 2022-03-31, the end of2022Q1, to 2023-03-31 is 365 days, with no February 29 in between, then 30, 31 and 30 days to 2023-06-30, the end of2023Q2.
DS_r := datediff(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 2022Q1 | 2023Q2 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
datediff(time_period, date) 🟢 · time_period, date → integer
Quarter end to a date 🟢 pandas ✅ · DuckDB ✅
- Tests:
datediff(SC_1, SC_2)of a time period and a date,SC_1= 2021Q2 andSC_2= 2021-11-04, the page’s valid syntaxdatediff (2021Q2, 2021-11-04).- Manual:
Days between two dates: “The last day of the time period is assumed as the starting/ending date”. The result is on the Extract time period page, whose Example 2, misplaced there, says that
datediff (2021Q2, 2021-11-04);“returns 127”.- Expected:
DS_r = 127, an Integer:2021Q2ends on 2021-06-30, then come 31, 31, 30, 31 and 4 days.
DS_r := datediff(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 2021Q2 | 2021-11-04 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗