Need a way to Ignore errors on query

Hello,

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.

Thank you

Can you share a snippet of code so we can see what you are trying to do?

Thank you...

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.

Thanks again

Hello @daniel :slight_smile:

MATCH (n_1:name_basics)
WHERE toInteger(substring(n_1.deathDate,0,2)) <= 12
AND toInteger(substring(n_1.birthDate,0,2)) <= 12
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

Regards,
Cobra

Thank you...

I will try that...