Add time unit to date · dateadd
---
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["Add time unit to date · dateadd<br/>🟢4"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_ds["dateadd(DS, n, p)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_comp["calc dateadd(comp, n, p)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc_date["dateadd(date, n, p)"]:::ok
v_sc_time_period["dateadd(time_period, n, p)"]:::ok
end
O --- G_ds
O --- G_comp
O --- G_sc
style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
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_ds href "#form-ds"
click v_comp href "#form-comp"
click v_sc_date href "#form-sc-date"
click v_sc_time_period href "#form-sc-time-period"
Types
Takes integer, time, date, time_period, duration · Gives time, date, any type
Comes from · integer, time, date, time_period, duration — 29 operators in 6 blocks 🟢29
General purpose operators (2) 🟢2
String operators (2) 🟢2
Numeric operators (4) 🟢4
Time operators (16) 🟢16
period_indicatorFill time series fill_time_seriesFlow to stock flow_to_stockStock to flow stock_to_flowTime shift timeshiftTime aggregation time_aggActual time current_dateDays between two dates datediffExtract the year getyearExtract the month getmonthExtract the day of the month dayofmonthExtract the day of the year dayofyearNumber of days to years and days daytoyearNumber of days to months and days daytomonthYears and days to number of days yeartodayMonths and days to number of days monthtodayAggregate and Analytic operators (2) 🟢2
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 34 operators in 7 blocks 🟢34
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Goes to: whatever takes its input's type
Goes to · time, date — 12 operators in 3 blocks 🟢12
General purpose operators (1) 🟢1
Time operators (10) 🟢10
Definitions (VTL-DL) (1) 🟢1
Goes to · operators that take any scalar — 49 operators in 9 blocks 🟢49
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Clause operators (9) 🟢9
Definitions (VTL-DL) (1) 🟢1
Forms
dateadd(DS, n, p) 🟢 · time, integer, duration → time, any type
Shifts the time identifier 🟢 pandas ✅ · DuckDB ✅
- Tests:
dateadd(DS_1, 1, "M"), the page’s valid syntaxDS_r := dateadd(DS_1, 1, “M”), on a dataset whose one time component is the date identifierId_2.- Manual:
Add time unit to date: the operand is
dataset{ identifier < time > _ , identifier _* }, and “the result Data Set has the same Identifier, Measure and Attribute Components as the operand Data Set”. The type names no time measure, only the time identifier, soId_2moves andMe_1is kept; the page does not say it in words, andDS_1allows no other reading.- Expected:
One month later, keeping the day as “
dateadd (2020-02-10, 1, “M”)gives2020-03-10”:2019-02-15and2020-03-10, every component keeping its type.
DS_r := dateadd(DS_1, 1, "M");
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2019-01-15 | 10 |
| B | 2020-02-10 | 20 |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2019-02-15 | 10 |
| B | 2020-03-10 | 20 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
calc dateadd(comp, n, p) 🟢 · date, time_period, integer, duration → date
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
dateadd(Me_1, 2, "M")insidecalc: two months after each date.- Manual:
Add time unit to date, Example 1, output verbatim: “adding months to a given date returns the date plus integer months”, and “In the component version, that can be used in a calc clause, a new component of type date is added to the dataset.”
- Expected:
Me_2is 2019-03-01, 2019-09-01 and 2021-02-28, two months after 2020-12-31 being the last day of February 2021.
DS_r:= DS_1[calc Me_2 := dateadd(Me_1, 2, "M")];
| Id_1 | Me_1 |
|---|---|
| G | 2019-01-01 |
| H | 2019-07-01 |
| T | 2020-12-31 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| G | 2019-01-01 | 2019-03-01 |
| H | 2019-07-01 | 2019-09-01 |
| T | 2020-12-31 | 2021-02-28 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
dateadd(date, n, p) 🟢 · date, integer, duration → date
One month later 🟢 pandas ✅ · DuckDB ✅
- Tests:
dateadd(SC_1, 1, "M")withSC_1= 2020-02-10: the date is an input scalar, as VTL has no date literal, and the period indicator a string, as in Manual example 1.- Manual:
Add time unit to date: “adding months to a given date returns the date plus integer months”, and “
dateadd (2020-02-10, 1, “M”)gives2020-03-10”.- Expected:
DS_r = 2020-03-10, a Date.
DS_r := dateadd(SC_1, 1, "M");
| SC_1 |
|---|
| 2020-02-10 |
Name |
Type |
Value |
|---|---|---|
|
Date |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
One year later 🟢 pandas ✅ · DuckDB ✅
- Tests:
dateadd(SC_1, 1, "A")withSC_1= 2020-02-10: one year added to a date.- Manual:
Add time unit to date: “adding years to a given date returns the date plus integer years; for years the “Y” is used”, and “
dateadd (2020-02-10, 1, “Y”)gives2021-02-10”.- Expected:
DS_r = 2021-02-10, a Date, the page’s result.- Adaptation:
The year is written
A, not the page’s “Y”: VTL prescribes no representation of durations, and the chapter’s list of period indicators givesAfor a year and says that “each VTL system can personalize the representation of time, date, time_period and duration as desired”. vtlengine’sdocs/data_types.rstgives the same codes for Duration, and the manual’s default conversion from string to duration (Type conversion) readsA,S,Q,M,WorD.
DS_r := dateadd(SC_1, 1, "A");
| SC_1 |
|---|
| 2020-02-10 |
Name |
Type |
Value |
|---|---|---|
|
Date |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
dateadd(time_period, n, p) 🟢 · time_period, integer, duration → date
From the last day of the quarter 🟢 pandas ✅ · DuckDB ✅
- Tests:
dateadd(SC_1, 5, "M")on a scalar time period,SC_1= 2022Q1, the page’s valid syntaxdateadd (2022Q1, 5, “M”).- Manual:
Add time unit to date: “The last day of the time period is assumed as the starting date”, and “The scalar version of this operator takes as input one date or time_period value and returns a date”.
- Expected:
DS_r = 2022-08-31, a Date:2022Q1ends on 2022-03-31, and “adding months to a given date returns the date plus integer months”: five months later is August 31, August having 31 days.
DS_r := dateadd(SC_1, 5, "M");
| SC_1 |
|---|
| 2022Q1 |
Name |
Type |
Value |
|---|---|---|
|
Date |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗