Forum Discussion

SnapWizard's avatar
SnapWizard
New Contributor III
5 years ago
Solved

Date.Parse() Function

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 Dat...
  • del's avatar
    5 years ago

    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.