String to Date conversion

I have a CSV file which has a date column with date and null, while converting the string to date using the Date.parse function getting NaN for null values. This works for the value which is date, if the value is null this is throwing NaN. How to deal with this?

Are you asking how to fallback to a default value in the null case? You can use the logical-OR operator (||) for such a thing. The operator will evaluate the left-side and, if it is “falsey”, it will return the result of the right-side. For example, if you wanted to use the current time when Date.parse() returned null or NaN, you can write:

Date.parse($column) ||

Or, if you wanted to return a fixed date, do something like this:

Date.parse($column) || Date.parse("2017-01-01T00:00:00")
1 Like

Thank you this worked. I used Date.parse($column) || null