Working with dates and times
The Test node has been updated using this Cypher statement:
cypher
MERGE (x:Test {id: 1})
SET
x.date = date(),
x.datetime = datetime(),
x.timestamp = timestamp(),
x.date1 = date('2022-04-08'),
x.date2 = date('2022-09-20'),
x.datetime1 = datetime('2022-02-02T15:25:33'),
x.datetime2 = datetime('2022-02-02T22:06:12')
RETURN x
Calculate days between two dates
Update this query to calculate the number of days between the date1
and date2
properties of the Test
node.
The difference between the two dates is the duration in days.
cypher
MATCH (x:Test)
RETURN ??????.??????(x.date1,x.date2).??????
Enter the number of days:
-
✓ 165
Hint
You will need to use the duration.inDays
function and return the number of days
between the two dates.
Make sure you have updated the Test
node before running the query.
Solution
The answer is 165
.
Run the following query to see the result:
cypher
MATCH (x:Test)
RETURN duration.inDays(x.date1,x.date2).days
Summary
In this challenge, you wrote a query to calculate the number of days between two dates.
In the next challenge, you will write another query related to datetime data.