cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot format date correctly to YYYY-MM-DD

NAl
Contributor

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.

12 REPLIES 12

bojanvelevski
Valued Contributor

Hello @NAl,

You can format the date with the following function:

Date.parse($original[‘Due Date’]).toLocaleDateString({“format”:“yyyy-MM-dd”})

image

Regards,

Bojan

NAl
Contributor

I’m afraid that’s throwing up an error:

Screen Shot 2021-04-09 at 2.01.25 PM

bojanvelevski
Valued Contributor

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’]

tlikarish
Employee
Employee

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)