cancel
Showing results for 
Search instead for 
Did you mean: 

Date.Parse() Function

SnapWizard
New Contributor III

I have an incoming file that has a date value of 00:00.00.000 as a value. I am trying to set it to null. Comparing the exit_date ==‘00:00:00.000’ fails. Checking Date.parse($exit_date)==’ ’ or Date.parse($exit_date==null fails. Date.parse($exit_date).ToLocalDateString() fails. Not sure how I can parse this data. Any ideas on how to map this value to null?

1 ACCEPTED SOLUTION

del
Contributor III

Try this expression in your mapper:

isNaN(Date.parse($.get('exit_date') || '')) ? null : Date.parse($exit_date).toLocaleDateTimeString()

Having not seen your entire input set, I can’t guarantee it will work for every record, but I think it will come very close, if not fully succeed.

The idea of this expression is:

If $exit_date exists and is translatable to dateobject, it will produce a datetime in which the LocaleDateTimeString() will result into a valid value; otherwise the result is null.

It is dependent on the expectation that NaN is always the result from Date.parse() for non-parsable parameters.

View solution in original post

6 REPLIES 6

SnapWizard
New Contributor III

Thank you. That worked.

viktor_n
Contributor II

Hi @SnapWizard,

As I see this is just a time not the whole date. And when you work only with time you should use LocalTime.parse() instead of Date.parse().