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: https://neo4j.com/docs/cypher-manual/current/functions/temporal/duration/#functions-duration-create-string
Format to use: https://neo4j.com/docs/cypher-manual/current/syntax/temporal/#cypher-temporal-specifying-durations

Maybe easier to create it with components: https://neo4j.com/docs/cypher-manual/current/functions/temporal/duration/#functions-duration-create-components

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