That date format is not supported by neo4j temporal date time functions. As such, you can parse it and convert it to a datetime value manually. The following script creates a node and then sets the datetime property only when the datetime value in the import is not null.
load csv with headers from "file:///Untitled.csv" as row
merge(n:TestNode{id: toInteger(row.id)})
with n, row
call (n, row) {
with row.date as date_value
where date_value is not null
with datetime({
day: toInteger(substring(date_value, 0, 2)),
month: toInteger(substring(date_value, 3, 2)),
year: toInteger(substring(date_value, 6, 4)),
hour: toInteger(substring(date_value, 11, 2)) + CASE WHEN substring(date_value, 20, 2) = "PM" THEN 12 ELSE 0 END,
minute: toInteger(substring(date_value, 14, 2)),
second: toInteger(substring(date_value, 17, 2)),
timezone: 'America/New York'
}) as converted_date
set n.dateValue = converted_date
}
return n
Test file:
Result:
You could use an APOC function to convert your date to a neo4j valid format, such that you could use the Neo4j datetime function. Here is an example:
with "10/01/2024 10:15:30 PM" as date_value
return datetime(apoc.date.convertFormat(date_value, "dd/MM/yyyy hh:mm:ss a", "yyyy-MM-dd'T'HH:mm:ss"))
Here is an example using apoc.periodic.iterate:
CALL apoc.periodic.iterate(
"
load csv with headers from 'file:///Untitled.csv' as row
return row
",
"
merge(n:TestNode{id: toInteger(row.id)})
with n, row
call (n, row) {
with row.date as date_value
where date_value is not null
with datetime({
day: toInteger(substring(date_value, 0, 2)),
month: toInteger(substring(date_value, 3, 2)),
year: toInteger(substring(date_value, 6, 4)),
hour: toInteger(substring(date_value, 11, 2)) + CASE WHEN substring(date_value, 20, 2) = 'PM' THEN 12 ELSE 0 END,
minute: toInteger(substring(date_value, 14, 2)),
second: toInteger(substring(date_value, 17, 2)),
timezone: 'America/New York'
}) as converted_date
set n.dateValue = converted_date}
",
{}
)