Why is DotLiquid or Azure Logic Apps automatically converting my date field?

Viewed 446

I have a liquid template that includes a date field, which I am not using any filters on at all, but it's getting converted from 2020-04-11T22:02:11Z UTC to 4/11/2020 10:02:11 PM. Is this expected behavior of DotLiquid or Azure Logic Apps? How can I prevent it from doing this?

2 Answers

I met the same problem in the past, liquid will convert the date time from 2020-04-11T22:02:11Z to 4/11/2020 10:02:11 PM automatically even if it is a string. As a workaround, we can use date format to convert it to the original date time.

For example, I have a json as below:

{
    "datetime": "2020-04-11T22:02:11Z"
}

We can use the liquid map like this:

{
    "datetime":"{{content.datetime | Date: "yyyy-MM-ddTHH:mm:ssZ"}}"
}

After that, we can get the original date format as 2020-04-11T22:02:11Z.

Hope it helps~

If you're running DotLiquid locally and using the Newtonsoft JSON deserializer then you can tell it not to parse date-time strings and to leave them as strings:

JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
    DateParseHandling = DateParseHandling.None
};

The Azure Logic Apps workflow engine seems to mirror this behaviour as my date-time strings aren't changed.

Related