# Apoc.date.parse date format doesn't work

**URL:** <https://community.neo4j.com/t/apoc-date-parse-date-format-doesnt-work/38283>\
**Category:** General\
**Tags:** apoc\
**Created:** [May 13, 2021, 5:42pm UTC](https://community.neo4j.com/t/apoc-date-parse-date-format-doesnt-work/38283 "2021-05-13T17:42:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tard\_gabriel](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tard_gabriel/32/28033_2.png) [@tard\_gabriel](https://community.neo4j.com/u/tard_gabriel)\
**Post date:** [May 13, 2021, 5:42pm UTC](https://community.neo4j.com/t/apoc-date-parse-date-format-doesnt-work/38283/1 "2021-05-13T17:42:34Z")

</div>

Hello there

This statement doesn't work, but according to everything in Neo4j doc, it should.

> RETURN apoc.date.parse('2020-11-14T18:22:06.327Z','s','yyyy-MM-ddThh:mm:ss.SSSZ')

yyyy-MM-ddThh:mm:ss.SSSZ Is a standard format

---

<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:** [May 13, 2021, 7:19pm UTC](https://community.neo4j.com/t/apoc-date-parse-date-format-doesnt-work/38283/2 "2021-05-13T19:19:05Z")

</div>

```auto
RETURN apoc.date.format(apoc.date.fromISO8601('2011-11-14T18:22:06.327Z'), 'ms', 'yyyy-MM-dd HH:mm:ss:zzz')
Result:
"2011-11-14 18:22:06:UTC"

```

---

<div class="post-metadata">

**Author:** ![tard\_gabriel](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tard_gabriel/32/28033_2.png) [@tard\_gabriel](https://community.neo4j.com/u/tard_gabriel)\
**Post date:** [May 13, 2021, 9:00pm UTC](https://community.neo4j.com/t/apoc-date-parse-date-format-doesnt-work/38283/3 "2021-05-13T21:00:48Z")

</div>

I actually needed to convert '2020-11-14T18:22:06.327Z' into seconds not ms.

But I found a workaround toInteger(apoc.date.fromISO8601('2011-11-14T18:22:06.327Z')/1000)

---

<div class="post-metadata">

**Author:** ![clem](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/clem/32/4364_2.png) [@clem](https://community.neo4j.com/u/clem)\
**Post date:** [May 14, 2021, 4:13pm UTC](https://community.neo4j.com/t/apoc-date-parse-date-format-doesnt-work/38283/4 "2021-05-14T16:13:39Z")

</div>

Fixed it!

I found when you look at the [Neo4J APOC documentation](https://neo4j.com/labs/apoc/4.1/overview/apoc.date/apoc.date.parse/) and it's a bit vague, see if you can find the corresponding Java documentation. (A lot of APOC is a wrapper to call standard Java Functions.)

Here is a better explanation with examples:  
[https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html)

You had two errors (as I far as I can see):

1. `Z` in the format string indicates the time zone offset. So, the parser is not expecting a `Z` in the input string but rather `+/-DD00`. To fix your input, I inserted `-0000` (to indicate GMT). I'm not sure what timezone offset you really wanted.
2. The `T` in the input string has to be matched with a quoted string in the format string. The parser barfed because `T` isn't a recognized letter that matches a time component (like `M` for month digit.) The fix is to use the quoted `'T'` in the format string to indicate a string literal.

Also, if you use `'s'` as the second argument, then your results will be in seconds.

```auto
RETURN apoc.date.parse(
        "2020-11-14T18:22:06.327-0000", // input string
        's', // 's' = seconds, 'ms' = milliseconds
        "yyyy-MM-dd'T'HH:mm:ss.SSSZ" // Format string
)
1605378126

```

---

<div class="post-metadata">

**Author:** ![tard\_gabriel](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tard_gabriel/32/28033_2.png) [@tard\_gabriel](https://community.neo4j.com/u/tard_gabriel)\
**Post date:** [May 14, 2021, 5:46pm UTC](https://community.neo4j.com/t/apoc-date-parse-date-format-doesnt-work/38283/5 "2021-05-14T17:46:54Z")

</div>

Thank you for the deep investigation @clem

---

<div class="post-metadata">

**Author:** ![tard\_gabriel](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tard_gabriel/32/28033_2.png) [@tard\_gabriel](https://community.neo4j.com/u/tard_gabriel)\
**Post date:** [May 14, 2021, 6:02pm UTC](https://community.neo4j.com/t/apoc-date-parse-date-format-doesnt-work/38283/6 "2021-05-14T18:02:27Z")

</div>

I can't modify the input string, the purpose of it it's to be able to optimise and use properly only one dedicated function to convert an ISO8601 date to a linux timestamp expressed in seconds.

But I figure it out by removing the Z from your format string.

RETURN apoc.date.parse('2021-12-11T09:42:09.327Z','s',"yyyy-MM-dd'T'hh:mm:ss.SSS")
