cancel
Showing results for 
Search instead for 
Did you mean: 

Date Issue

amit_saroha
New Contributor III

Hi All,
I have 3-4 date columns with not null and with null date values in mm/dd/yyyy format. I have used the below expression in mapper snap to format the date but facing the below issue. Could anyone suggest what correction is needed?

Date.parse($[‘Actual termination date’]!= null ? $[‘Actual termination date’].toString().substr(0,9) : $[‘Actual termination date’]).toLocaleDateString({“format”:“yyyy-MM-dd”})

“error”:
“Invalid timestamp format: 2022-04-20”

“reason”:
“Time should be in format “yyyy-[m]m-[d]d hh:mm:ss[.f…]”. The fractional seconds may be omitted. The leading zero for mm and dd may also be omitted.”

1 ACCEPTED SOLUTION

SpiroTaleski
Valued Contributor

@amit.saroha

If you need to handle both scenarios(with null and without null date values), probably you will need first to check if ‘Actual termination date’ is not null then do the date parsing and formatting, otherwise send null(or any other value in case Actual termination date is null).

$.hasPath("['Actual termination date']") ? Date.parse($[‘Actual termination date’]).toLocaleDateString({“format”:“yyyy-MM-dd”}) : "any other value in case actual termination date is null"

BR.
Spiro Taleski

View solution in original post

2 REPLIES 2

SpiroTaleski
Valued Contributor

@amit.saroha

If you need to handle both scenarios(with null and without null date values), probably you will need first to check if ‘Actual termination date’ is not null then do the date parsing and formatting, otherwise send null(or any other value in case Actual termination date is null).

$.hasPath("['Actual termination date']") ? Date.parse($[‘Actual termination date’]).toLocaleDateString({“format”:“yyyy-MM-dd”}) : "any other value in case actual termination date is null"

BR.
Spiro Taleski

amit_saroha
New Contributor III

Hi @Spiro_Taleski - Thanks, it doesn’t work when the whole column has null values.

failure:

“Not-a-number (NaN) does not have a method named: toLocaleDateString, found in: …-dd HH:mm:ss”}). Perhaps you meant: toString, toExponential, toPrecision, toFixed"

value:

“Handle the NaN value by providing a default value, for example: (Date.parse($[‘DateTo’]!= null ? $[‘DateTo’].toString().substr(0,10) : $[‘DateTo’]) || /* default */).toLocaleDateString({“format”:“yyyy-MM-dd HH:mm:ss”})”

reason:

“Handle the NaN value by providing a default value, for example: (Date.parse($[‘DateTo’]!= null ? $[‘DateTo’].toString().substr(0,10) : $[‘DateTo’]) || /* default */).toLocaleDateString({“format”:“yyyy-MM-dd HH:mm:ss”})”