I need a way to ignore nodes where there is an error when converting a string to a date using date(). If the source string does not meet the required format, I would like cypher to skip the node instead of throwing an error. I tried also using apoc date parser but still an exception is thrown when the format is not correct.
match (n_1:name_basics)
return duration.inMonths(date({year:toInteger(substring(n_1.deathDate,6,4)),
month:toInteger(substring(n_1.deathDate,0,2)),
day:toInteger(substring(n_1.deathDate,3,2))}),
date({year:toInteger(substring(n_1.birthDate,6,4)),
month:toInteger(substring(n_1.birthDate,0,2)),
day:toInteger(substring(n_1.birthDate,3,2))})).months/12 as D1 limit 100
where both birthDate and deathDate are strings, and almost all are of the form MM/DD/YYYY, but there are some that are of the form DD/MM/YYYY and thus throw an error when the month is grater than 12. I would like cypher just to skip such a case and keep processing the rest.