← cast operator page · general/cast/time_period_to_date/daily_periods

Daily periods 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

cast(Me_1, date) on a Time_Period measure of daily periods, an explicit cast without mask.

Manual:

Type conversion: "From time_period to date: A date value is returned if the input time_period has a duration of a single day, representing that day; otherwise an error is raised."

Expected:

2020D15 gives 2020-01-15 and 2020D61 gives 2020-03-01, 2020 being a leap year; both are daily, so neither raises the error.

script.vtl ⇩

DS_r := DS_1[calc Me_2 := cast(Me_1, date)];

input/DS_1.csv ⇩

Id_1Me_1
12020D15
22020D61

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Time_Period", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_1Me_2
12020D152020-01-15
22020D612020-03-01

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Me_1", "type": "Time_Period", "role": "Measure"},
        {"name": "Me_2", "type": "Date", "role": "Measure"}
      ]
    }
  ]
}