← datediff operator page · time/datediff/comp_comp/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

datediff(Id_2, Me_1) inside calc, 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:

2020Q2 ends on 2020-06-30 and 2021Q1 on 2021-03-31, so Me_2 is 546, 639 and 90, Integers.

script.vtl ⇩

DS_r:= DS_1[calc Me_2 := datediff(Id_2, Me_1)];

input/DS_1.csv ⇩

Id_1Id_2Me_1
G2019-01-012020Q2
G2019-07-012021Q1
T2020-12-312021Q1

input/DS_1.json ⇩

{
  "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}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Me_1Me_2
G2019-01-012020Q2546
G2019-07-012021Q1639
T2020-12-312021Q190

expected/DS_r.json ⇩

{
  "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"}
      ]
    }
  ]
}