Cypher now has great support for creating and comparing date time instances. Can we expect to see new functions for formatting these?
Have you had a look at the APOC date parsing/formatting functions?
Hi taffyb,
You should be able to use the apoc library methods: apoc.date.parse() and apoc.date.format() to achieve what you are looking for.
As an example, to convert the current timestamp in epoch that is returned by timestamp()
function to a friendly format, you could do
WITH apoc.date.format( timestamp(), 'yyyyMMdd HH:mm:ss.ms') AS initialTime RETURN initialTime
Documentation can be found here: Neo4j APOC Procedures User Guide
Yes I have used apoc to do this. However currently (as far as I can tell) it requires me to get the timestamp or epoch value then format. I was hoping there might be something a bit more native.
You can declare dates in UTC format and get it back as epoch as well using datetime().
WITH datetime('2015-07-21T21:40:32.142+0100') AS date1 RETURN date1.epochMillis
I am not sure what your exact use-case is, but to feed a date into a query you have to use one of these formats:
- epoch millis
- UTC date string
- A full date object, specifiying the timezone information:
WITH datetime({ year:1984, month:11, day:11, hour:12, minute:31, second:14, nanosecond: 645876123, timezone:'Europe/Stockholm' })
Hi taffyb,
This is something we'd like to see for our native temporal types, as the date formatting for APOC is convenient.
I believe this is on our backlog, though I'll confirm (and make sure it is if not).
Andrew
Native formating seems to be a natural addition. However changes to the apoc routines to accept temporal types as input might be another approach.