How to store duration

Hi,

I need to store input string 23:12:58 as duration in Neo4j node properties.
Like:
Match(n:Per{consumedTime:duration('23:12:58')})

Regards
Vivek

To create duration from a string: Temporal functions - duration - Cypher Manual
Format to use: Temporal (Date/Time) values - Cypher Manual

Maybe easier to create it with components: Temporal functions - duration - Cypher Manual

duration({hours: 23, minutes:12, seconds: 58}) ?

1 Like
RETURN duration({hours: 23, minutes: 12, seconds:12}) as duration
╒══════════════╕
│"duration"    │
╞══════════════╡
│"P0M0DT83532S"│
└──────────────┘


WITH duration({hours: 23, minutes: 12, seconds:12}) as duration
MATCH (n:Per {consumedTime: duration}) 
RETURN n

I should store it as 'PT23H12M58S' string in this format, then you can do calculations like this:
RETURN duration('PT23H12M58S').seconds;

It will give you the duration in seconds (83578 s).

Thanks a lot it worked.

1 Like