04-09-2021 05:09 AM
Hi there,
I’ve looked at other articles addressing this but non has helped me so far.
Im looking to format a date in the DD/MM/YYYY to YYYY-MM-DD.
The date will always be populated.
I’ve tried the following expressions but they wont process correctly
Date.parse($original[‘Due Date’], “yyyy MM dd”)
LocalDate.parse($original[‘Due Date’],“yyyy/MM/dd”)
If I use the above expression and if the date is 06/04/2021, the output date becomes 0006-04-18. It’s inexplicable.
04-09-2021 05:45 AM
Hello @NAl,
You can format the date with the following function:
Date.parse($original[‘Due Date’]).toLocaleDateString({“format”:“yyyy-MM-dd”})
Regards,
Bojan
04-09-2021 06:02 AM
I’m afraid that’s throwing up an error:
04-09-2021 06:06 AM
Please check for syntax errors. As I can see from the suggestions, your date field from the incoming data comes directly as a $[‘Due Date’] and not $original[‘Due Date’]
04-09-2021 07:57 AM
The second argument to parse is the format that the string is expected to be in and that’s why you get the 0006-04-18 result.
Here’s an example pipeline to try out. It includes a mapper with the expression @bojanvelevski mentioned and also another method using the Date Time Extractor snap from the ML Data Preparation snap pack.
date-example_2021_04_09.slp (7.0 KB)