Lode
Lode

Reputation: 63

Total minutes in a duration in Neo4J

I recently wanted to know the difference in minutes and/or hours in a duration.between in neo4j.

MATCH (yv:YoutubeVideo)
WHERE datetime(yv.publishedAt) >= datetime('2021-11-16T12:05:47.897962')
WITH yv, duration.between(datetime('2021-11-16T12:05:47.897962'), yv.publishedAt).minutes as minutes,
yv.publishedAt as expectedDate,
datetime('2021-11-16T12:05:47.897962') as startDate
RETURN duration.between(datetime('2021-11-16T12:05:47.897962'), yv.publishedAt) as duration, startDate,
expectedDate + duration({minutes:minutes}) as expectedRes,
startDate + duration({minutes:minutes})as  resultDate
LIMIT 1

This gives result: enter image description here

This seems to be okay, but it isn't. As you can see I want to add the minutes of the duration to startDate to get the expectedRes. I realized that the duration.between(datetime('2021-11-16T12:05:47.897962'), yv.publishedAt).minutes returns only the minutes in the hour, not including the days. Which results in resultDate.

A better example: Say the duration is 3 days, 4 hours en 20 minutes. If I do .minutes, I'll receive 260 minutes as result (This is the result of hours * minutes in an hour + leftover minutes, in this case 4 * 60 + 20), but I want the result to be 4580 (This is the result of (days * hours + leftover hours) * minutes in an hour + leftover minutes, in this case (3 * 24 + 4) * 60 + 20 )

Is there a way to get the total minutes of the duration (including the days) without doing that equation in my Cypher query?

Upvotes: 0

Views: 548

Answers (1)

David A Stumpf
David A Stumpf

Reputation: 793

Take a look at apoc temporal or apoc dates.

Upvotes: 1

Related Questions