Transform Query: Add X days to today, and convert to MM-dd-yyyy

Hi,
I need some help debugging an issue with the following transform:

{
    "name": "Test Date Transform Delete Later",
    "type": "static",
    "attributes": {
        "date": {
            "attributes": {
                "input": {
                    "attributes": {
                        "expression": "now+73d"
                    },
                    "type": "dateMath"
                },
                "inputFormat": "ISO8601",
                "outputFormat": "MM-dd-yyyy"
            },
            "type": "dateFormat"
        },
        "value": "$date"
    },
    "internal": false
}

I am trying to add X days (78 in this example) to today’s date, and convert to MM-dd-yyyy.
I keep getting a “error in calculating $date” error. Do you see an issue here?

Here’s a list of variations I tried:

  1. adding an input with an empty object
  2. adding an input with an empty string
  3. using roundUp flag with true as well as with false, and using “now+78d/d” as the expression.

None of the above worked, and I keep getting the error. If I were to just do a dateMath operation, I can see the value does show up, but it fails when I pass the output to the dateFormat operation.

The output format for the DateMath transform is “yyyy-MM-dd’T’HH:mm”. When you use this transform inside another transform (e.g., dateCompare), make sure to convert to ISO8601 first.

1 Like

Try flipping your input and output format

This is how we have our transforms set up doing date compares:

“inputFormat”: “yyyy-MM-dd”,
“outputFormat”: “ISO8601”

1 Like

Thanks @sharvari
I was assuming dateMath output was in ISO8601, but it outputs in the format as described here:

Updating the transform to use that format for the input worked as expected:

{
    "name": "Test Date Transform Delete Later",
    "type": "static",
    "attributes": {
        "date": {
            "attributes": {
                "input": {
                    "attributes": {
                        "expression": "now+73d"
                    },
                    "type": "dateMath"
                },
                "inputFormat": "yyyy-MM-dd'T'HH:mm",
                "outputFormat": "MM-dd-yyyy"
            },
            "type": "dateFormat"
        },
        "value": "$date"
    },
    "internal": false
}

Thank you!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.