← cast operator page · general/cast/date_to_string_mask/optional_digits

Optional digits 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

cast(Me_1, string, "{D}D/{M}M/YYYY") on a Date measure: braces around the digit of the day and of the month that may be left out.

Manual:

Type Conversion and Formatting Mask: "If the numerical representation is not padded, the optional digits that can be omitted (if equal to zero) are enclosed within braces; for example {M}M means that April is represented by 4 and December by 12".

Expected:

5/4/2018, 31/12/2021 and 15/1/2020: a day or a month below 10 is written with one digit, where DD and MM would pad it with a zero.

script.vtl ⇩

DS_r := DS_1[calc Me_2 := cast(Me_1, string, "{D}D/{M}M/YYYY")];

input/DS_1.csv ⇩

Id_1Me_1
12018-04-05
22021-12-31
32020-01-15

input/DS_1.json ⇩

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

expected/DS_r.csv ⇩

Id_1Me_1Me_2
12018-04-055/4/2018
22021-12-3131/12/2021
32020-01-1515/1/2020

expected/DS_r.json ⇩

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