cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Date Conversion from String to Date format fails with error: Wrong argument type: Can't coerce `2009-07-30` to String

MalteR
Node Link

Actually I am trying to convert String formats into dates and following format occur:

  1. "30-JUL-2009"
  2. "31/12/2018"
  3. "n"
  4. 2009-07-30
    these Strings that are to be formatted as dates occur in a relationship as attributes.
    Trying to match them with a regular expression as follows fails and I donnot have any idea why:
match(n:ENTITY)-[r:VALIDITY_PERIOD]-(m:ENTITY)
where apoc.meta.type(r.end_date) =  "STRING" 
and not r.end_date = "2009-07-30"
and trim(r.end_date) =~'^[0-9]{2}-[A-Z]{3}-[0-9]{4}$'
set r.end_date = date(datetime({epochmillis: apoc.date.parse(r.end_date, "ms", "dd-MMM-yyyy")})) return r;

this actually is my try to match and update format no 1.
it fails with the following error message:

Neo.ClientError.Statement.TypeError

Wrong argument type: Can't coerce `2009-07-30` to String

I tried with or without starting and ending string markes, both fail with same error.

Anyone who can help me out here?

Thank you and kindest regards,
Malte

3 REPLIES 3

I think you want the apoc.date.parseAsZonedDateTime function:

WITH apoc.date.parseAsZonedDateTime( "2009-07-30", 'YYYY-MM-dd') AS date
RETURN date, apoc.meta.type(date), date(date), apoc.meta.type(date(date))

Hello Mark,

MATCH (n)-[r:VALIDITY_PERIOD]-(n)
WHERE not r.start_date = '-'
WITH apoc.date.parseAsZonedDateTime(r.start_date, 'YYYY-MM-dd') AS date
RETURN date, apoc.meta.type(date), date(date), apoc.meta.type(date(date))

trying the adapted statement above leads to the following error

Neo.ClientError.Statement.TypeError

Wrong argument type: Can't coerce 2005-01-26 to String

MalteR
Node Link

Hello all,
thanks a lot for researching, actually the following statement worked with serveral adaptions for each case:

match(n:ENTITY)-[r:VALIDITY_PERIOD]-(n:ENTITY)
where apoc.meta.type(r.start_date) =  "STRING" 
and trim(r.start_date) =~'^[0-9]{2}.*[0-9]{2}.*[0-9]{4}$'
set r.start_date = date(datetime({epochmillis: apoc.date.parse(r.start_date, "ms", "dd/MM/yyyy")}))
return r.start_date limit 5;

So problem solved:

actualy most likely the errors were caused by the part the where clause which was introduced by

and not r.end_date = "2009-07-30"

This seems to have caused the issues.
Best regards,
Malte R

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online