Reputation:
I am looking to find a birth_date between a range using timestamp (long value) in neo4j. Here I am matching the user, with id 10662 . Along with other users, with date_birth in the range between +3 and -3 years of the u.date_birth
The value of 10800000 is the 3 years in milliseconds, but I am not getting any results, I am sure something is wrong. But not able to locate the problem.
I would appreciate any help.
match (u:user {id : "10662"})-[r:has_profile]->(p:profile) , (u2:user)-[r2:has_profile]->(p2:profile) where p.user_id <> p2.user_id and u2.date_birth >= u.date_birth -toInt(10800000) and u2.date_birth <= u.date_birth + toInt(10800000) return collect (u2.id) as id;
Upvotes: 2
Views: 812
Reputation: 66999
3 years in milliseconds (assuming 365 days per year) is actually 94608000000.
Does this work for you?
MATCH (u:user {id : "10662"})-[r:has_profile]->(p:profile), (u2:user)-[r2:has_profile]->(p2:profile)
WHERE
p.user_id <> p2.user_id AND
abs(u2.date_birth - u.date_birth) >= 94608000000
RETURN collect(u2.id) as id;
Upvotes: 2
Reputation:
This works too:
match (u:user {id : "10662"})
, (u2:user)-[r2:has_profile]->(p2:profile)
where
p.user_id <> p2.user_id
and u2.date_birth >= u.date_birth -94608000000
and u2.date_birth <= u.date_birth +94608000000
return collect (u2.id) as ids
AS You correctly pointed out, there was a problem with the value of 3 years in milliseconds. Thank you!
Upvotes: 0