cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Finding data from a set time frame

I couldn't find anything on this, I have dates example Mon 17 Jan 10:09:01, I am finding how many kids was born during Sat 10 March 10:05am - 10:10am is there a way without usinga ton of Where date = "Sat 10 March 10:05:01". is there a better way?

4 REPLIES 4

Please define your data set, current query and expected results.
I could hardly understand anything of what you have posted.

WHERE name.Date=	"Mon 18 Feb 2019 20:10:00"	or name.Date=	"Mon 18 Feb 2019 20:10:01"	or name.Date=	"Mon 18 Feb 2019 20:10:02"	or name.Date=	"Mon 18 Feb 2019 20:10:03"	or name.Date=	"Mon 18 Feb 2019 20:10:04" 

this is just like 1/10 of the where statements is there away just to set min and max like sql?

you could convert the dates (including those with which you are doing the comparison) to their number correspondents and work from there https://neo4j.com/docs/labs/apoc/current/temporal/datetime-conversions/

Assuming you were using properties that are orderable (such as temporal types, epoc timestamps, or string dates that order correctly, unlike the example you provided), you can add an index on the property in question, and use a range index lookup.

One problem however is that the times you provided do not include the year. All of the time representations I mentioned earlier are absolute, a time representation of an instant, including the year.

If you want a relative time representation, independent of the year, then a String representation might work best instead of the others. For example: "05/10 10:05" (you should be using 24 hour time and not using am/pm so that the times are properly orderable). This would probably be in addition to a proper timestamp, as other use cases would likely work better with an instant of time rather than this year-independent representation.

So, let's say we have nodes like this:

(:Person {relativeDOB:"05/10 10:07"})

Then we would want an index on this:

CREATE index on :Person(relativeDOB)

After we have the index, we can perform an index range lookup:

WITH "05/10 10:05" as start, "05/10 10:10" as end
MATCH (p:Person)
WHERE start <= p.relativeDOB <= end
RETURN count(p) as kidsBornInRange

This is of course regardless of year, just looking at the month/date/time range.

If the actual use case includes the year, then you can disregard most of what I said about year-independent values, and just use regular dateTime or timestamp types instead, the query will be relatively the same, you'll just define the start and end times with the appropriate types.