cancel
Showing results for 
Search instead for 
Did you mean: 

Need to convert yyyymmdd to yyyy-mm-dd

Sahil
Contributor

Hi,
I have a element as:-
jsonPath($, “$Z_ORD.IDOC.DK02[].DATE")
and value is coming as 20210521(yyyymmdd).
I need to convert it to 2021-05-21 and map it to target ml element.
I am using mapper. Tried like below:-
Date.parse(jsonPath($, "$Z_ORD.IDOC.DK02[
].DATE”,“yyyMMdd”)).toLocaleDateTimeString({“format”:“yyyy-MM-dd”}) || null

but getting error as:-
Not-a-number (NaN) does not have a method named: toLocaleDateTimeString, found in: …:“yyyy-MM-dd”}). Perhaps you meant: toString, toExponential, toPrecision, toFixed

1 ACCEPTED SOLUTION

bojanvelevski
Valued Contributor

I ment at the end of my expression which parsed your date.

Date.parse($Z_ORD.IDOC.DK02.map(x=>x.DATE.toString().substring(0,4)).concat($Z_ORD.IDOC.DK02.map(x=>x.DATE.toString().substring(4,6)),$Z_ORD.IDOC.DK02.map(x=>x.DATE.toString().substring(6))).join(“-”)).toLocaleDateString()

View solution in original post

7 REPLIES 7

Hi @bojanvelevski ,
I already tried using toLocaleDateString but it is throwing error:-
Not-a-number (NaN) does not have a method named: toLocaleDateTimeString, found in: …:“yyyy-MM-dd”}). Perhaps you meant: toString, toExponential, toPrecision, toFixed

bojanvelevski
Valued Contributor

I ment at the end of my expression which parsed your date.

Date.parse($Z_ORD.IDOC.DK02.map(x=>x.DATE.toString().substring(0,4)).concat($Z_ORD.IDOC.DK02.map(x=>x.DATE.toString().substring(4,6)),$Z_ORD.IDOC.DK02.map(x=>x.DATE.toString().substring(6))).join(“-”)).toLocaleDateString()

@bojanvelevski
Thank you, it worked.