Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-12-2020 09:19 AM
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
01-12-2020 02:25 PM
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')
01-12-2020 05:18 PM
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"
04-07-2020 06:49 AM
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')})
11-27-2021 03:27 AM
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'))
All the sessions of the conference are now available online