# Datetime issue - Import data from SQL Server

**URL:** <https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400>\
**Category:** ETL-Tool\
**Created:** [September 11, 2018, 7:17am UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400 "2018-09-11T07:17:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![harvey\_nguyen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/harvey_nguyen/32/3290_2.png) [@harvey\_nguyen](https://community.neo4j.com/u/harvey_nguyen)\
**Post date:** [September 11, 2018, 7:17am UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/1 "2018-09-11T07:17:22Z")

</div>

I am using `neo4j-admin import` tool to import data from large csv files. These files are exported from SQL Server.  
The problem that I am facing is different format between SQL and Neo4j:

In SQL Server, datetime field is: `2018-08-16 01:15:34.500`  
When I import data, it has an error: `Text cannot be parsed to a DateTime`

Because using neo4j import tool, I cannot use any apoc or something like that to reformat this string  
How can I solve this ? (I am using Neo4j community 3.4.7)  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ryan.boyd](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ryan.boyd/32/60_2.png) [@ryan.boyd](https://community.neo4j.com/u/ryan.boyd)\
**Post date:** [September 11, 2018, 9:14pm UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/2 "2018-09-11T21:14:31Z")

</div>

Hi Harvey,

Ah, it's probably an issue with the milliseconds there.

Suggest importing as a string into a temp property and then using Cypher to update all the nodes and set the real date-time property.

Cheers,  
-Ryan

---

<div class="post-metadata">

**Author:** ![harvey\_nguyen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/harvey_nguyen/32/3290_2.png) [@harvey\_nguyen](https://community.neo4j.com/u/harvey_nguyen)\
**Post date:** [September 12, 2018, 1:41am UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/4 "2018-09-12T01:41:43Z")

</div>

Hi Ryan,  
Thanks for your reply,

So I have to use some tricks in this case. However, I think Neo4j should be enhanced to handle `Datetime` well in next versions.

Thanks.  
Harvey

---

<div class="post-metadata">

**Author:** ![ryan.boyd](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ryan.boyd/32/60_2.png) [@ryan.boyd](https://community.neo4j.com/u/ryan.boyd)\
**Post date:** [September 13, 2018, 4:41pm UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/5 "2018-09-13T16:41:46Z")

</div>

Agreed that it’d be good if we could specify a datetime format string along with the type.

Will put in that request.

Cheers  
Ryan

---

<div class="post-metadata">

**Author:** ![benjamin.squire](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/benjamin.squire/32/1496_2.png) [@benjamin.squire](https://community.neo4j.com/u/benjamin.squire)\
**Post date:** [October 12, 2018, 9:18pm UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/6 "2018-10-12T21:18:15Z")

</div>

I am having the same issue. Lets Can we improve datetime Function for Epoch timestamps as well?

---

<div class="post-metadata">

**Author:** ![yudiellhernandez](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/yudiellhernandez/32/2313_2.png) [@yudiellhernandez](https://community.neo4j.com/u/yudiellhernandez)\
**Post date:** [November 29, 2018, 8:42pm UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/7 "2018-11-29T20:42:49Z")

</div>

The issue seems to be the space between the date and the time. Replacing the space for "T" fixed the issue for me.  
MATCH(n:Node) RETURN datetime( REPLACE(n.DateTime," ","T"))

---

<div class="post-metadata">

**Author:** ![julian.n.de.jonge](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/julian.n.de.jonge/32/3870_2.png) [@julian.n.de.jonge](https://community.neo4j.com/u/julian.n.de.jonge)\
**Post date:** [October 23, 2020, 8:25am UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/8 "2020-10-23T08:25:09Z")

</div>

Thanks, found this really helpful. Not sure if anyone else had the same issue, but I found replacing the space with a "T" imports this column as a string, not a datetime type. Therefore it still needs to be converted into a datetime series after.

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [October 25, 2020, 4:13am UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/9 "2020-10-25T04:13:06Z")

</div>

```auto
Try this:

with "2018-08-16 01:15:34.500" as dte
RETURN apoc.date.format(apoc.date.parse(dte, 'ms', 'yyyy-MM-dd'), 'ms', 'yyyy-MM-dd')

result:
"2018-08-16"

During import from csv file replace 'dte' with date column say row.date.

```

---

<div class="post-metadata">

**Author:** ![senthilc78](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@senthilc78](https://community.neo4j.com/u/senthilc78)\
**Post date:** [November 4, 2020, 1:09pm UTC](https://community.neo4j.com/t/datetime-issue-import-data-from-sql-server/1400/10 "2020-11-04T13:09:59Z")

</div>

Faced same issue but below code works for me without apoc .

1. SPLIT milliseconds separate
2. Replace space btw Date and time with "T"

Eg.  
LOAD CSV WITH HEADERS FROM "file:///sourcepath.csv" AS csvRecord

RETURN datetime(REPLACE(SPLIT(csvRecord.dt,".")[0]," ","T"))

CSV date field dt contains "2020-01-25 16:18:24.000"

Result : "2020-01-25T 16:18:24Z" .

Hope it helps!
