06-06-2021 04:34 AM
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
Solved! Go to Solution.
06-06-2021 01:54 PM
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()
06-06-2021 07:40 AM
Hi @Sahil,
I presume the jsonPath should look like this : jsonPath($, “$Z_ORD.IDOC.DK02[*].DATE”). The value from this jsonPath is an array, so to get it, you have to go with .toString() or with indexing [0]. Even than, Date.parse() would return incorrect date, because 20210521 will be treated as an integer of milliseconds since midnight January 1, 1970 UTC. You can use one of the following expressions to get the right format:
Date.parse([…jsonPath($, “$Z_ORD.IDOC.DK02[].DATE").toString().substring(0,4),jsonPath($, "$Z_ORD.IDOC.DK02[].DATE”).toString().substring(4,6),jsonPath($, “$Z_ORD.IDOC.DK02[*].DATE”).toString().substring(6)].join(“-”))
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(“-”))
Hope this helps,
Regards,
Bojan
06-06-2021 08:24 AM
Hi,
Thank you for the reply.
1st option was throwing error so I tried 2nd one but getting date as
2021-03-17T00:00:00.000 UTC
it should be just, please let me know how do I rectify it.
2021-03-17
06-06-2021 08:47 AM
06-06-2021 01:22 PM
Use the following method : .toLocaleDateString()
Or you can add a specific format : .toLocaleDateString({“format”:“yyyy/MM/dd”})