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.

Transforming data format when using LOAD CSV

Hi all. I'm using LOAD CSV to read CSV files and append regular Cypher statements to create or update the data as a graph. One of the columns withinh the CSV source has date values formated as 'yyyy-MM-dd'. I want to transform them from string into datetime, and, at the same time, into dd/MM/yyyy format when importing into my Neo4j database. Is there any solution with LOAD CSV?
Miquel Centelles

4 REPLIES 4

Pass the row's date string into apoc.date.parse to convert it to a workable format, e.g milliseconds:

with apoc.date.parse(row['date'], 'ms', 'yyyy-MM-dd') as evenTs

and then use apoc.date.format to put that value into the format you want:

return apoc.date.format(eventTs, 'ms', 'dd/MM/YYYY')

APOC date & time conversion docs

mcentellsev is right. My suggestion is just an addendum.

You can combine them into one query like:

RETURN apoc.date.format(apoc.date.parse("2019-09-08T17:46:10Z", 'ms', 'yyyy-MM-dd'), 'ms', 'yyyy-MM-dd')

Result: "2019-09-08"

If you want to import the date as a Neo4j datetime, the following works:

datetime({epochMillis:apoc.date.parse(row['date'],'ms', 'yyyy-MM-dd')})

I managed this by using the following approach:

LOAD CSV WITH HEADERS FROM "https://yourdomain.com/yourfile.csv" AS row
MERGE (n:EntityName {id: row.id})
SET n.YourDateFieldName = date(apoc.date.format(apoc.date.parse(row.YourDateFieldName,'ms', 'dd/mm/yyyy'),'ms','yyyy-mm-dd'))