# Import csv format issue: convert str date to datetime format

**URL:** <https://community.neo4j.com/t/import-csv-format-issue-convert-str-date-to-datetime-format/68393>\
**Category:** Import / Export\
**Created:** [June 14, 2024, 3:36pm UTC](https://community.neo4j.com/t/import-csv-format-issue-convert-str-date-to-datetime-format/68393 "2024-06-14T15:36:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonitawl](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bonitawl/32/31753_2.png) [@bonitawl](https://community.neo4j.com/u/bonitawl)\
**Post date:** [June 14, 2024, 3:36pm UTC](https://community.neo4j.com/t/import-csv-format-issue-convert-str-date-to-datetime-format/68393/1 "2024-06-14T15:36:27Z")

</div>

hi there,

i have a csv file where it contains ID, source node, target node, date, sentiment. i would like to load it into neo4j, but when i load the csv file, it will read my date as string. i tried to change to datetime(row.date) or date(row.date) .  
but no luck, giving me error  
Text cannot be parsed to a DateTime "7/1/2020"

Here is my sample of csv:  
ID,source,target,date,sentiment  
1,a,b,7/1/2020,positive  
2,a,c,7/1/2020,negative

LOAD CSV WITH HEADERS FROM 'file:///test.csv' AS row  
MERGE (source:Character {name: row.source})  
MERGE (target:Character {name: row.target})  
WITH source, target, row  
MERGE (source)-[r:INTERACTS {date: datetime(row.date), sentiment: row.sentiment}]-\>(target)

how would i have to change my date columns to my csv file so that it can parse a datetime into neo4j ? or how would i able to convert the date columns into datetime in neo4j?

please advise!! thanks!!

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [June 14, 2024, 10:37pm UTC](https://community.neo4j.com/t/import-csv-format-issue-convert-str-date-to-datetime-format/68393/2 "2024-06-14T22:37:49Z")

</div>

The date format you are using is not supported by the "datetime" method. One option is to parse the data string into its components and pass a map to the date method.

Note, I used "date" instead of "datetime" as you did not have a time component. Using datetime with just a date will just add "zero" time UTC to the date.

```auto
LOAD CSV WITH HEADERS FROM 'file:///Book1.csv' AS row
WITH row, split(row.date, "/") as date
WITH row, datetime({
    year:toInteger(date[2]), 
    month:toInteger(date[0]),
    day:toInteger(date[1])
}) as convertedDate
MERGE (source:Character {name: row.source})
MERGE (target:Character {name: row.target})
MERGE (source)-[r:INTERACTS {date: convertedDate, sentiment: row.sentiment}]->(target)

```

Note: you could avoid the extra work if you could change your import file to provide the date in yyyy-mm-dd format instead, as this is one of the supported formats of the “date” procedure.

---

<div class="post-metadata">

**Author:** ![bonitawl](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bonitawl/32/31753_2.png) [@bonitawl](https://community.neo4j.com/u/bonitawl)\
**Post date:** [June 17, 2024, 5:22am UTC](https://community.neo4j.com/t/import-csv-format-issue-convert-str-date-to-datetime-format/68393/3 "2024-06-17T05:22:33Z")

</div>

it works!!! thanks so much 😃
