DateTime comparison in WHERE condition
See original GitHub issueHello, I’m trying to use Neo4jClient to implement a few basic queries and some obstacles came along when I tried to query Neo4j datetime properties with .NET datetime objects. Let’s assume I have the following model:
public class Something
{
[Neo4jDateTime]
[JsonProperty("arrival_date_time")]
public DateTime Arrival { get; set; }
[Neo4jDateTime]
[JsonProperty("departure_date_time")]
public DateTime Departure { get; set; }
}
…and the following query:
DateTime arrival = DateTime.Parse("2019-03-22T10:00:00");
var query = client.Cypher
.Match($"(thing:{typeof(Something).Name})")
.Where((Something thing) => thing.Arrival > arrival)
.Return<Something>("thing");
This produces the following Neo4j query:
MATCH (thing:Something)
WHERE (thing.arrival_date_time > "2019-03-22T10:00:00")
RETURN thing
…which seems to be incorrect as in order to get the correct result, the query parameter should be parsed to Neo4j DateTime object, as below:
MATCH (thing:Something)
WHERE (thing.arrival_date_time > datetime("2019-03-22T10:00:00"))
RETURN thing
Am I doing something wrong or is it a bug?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to Compare 2 Dates in the WHERE Clause in SQL
When comparing dates, use regular comparison operators: < , > , = , <= , >= . In this example, you'll want to...
Read more >Compare two dates inside the where clause - sql
Compare two dates inside the where clause · 1 · Use DATEADD(HOUR,10, DateCreated) in where clause instead of X · okay..i am query...
Read more >How to compare with only dates and ignore time in where ...
I write the query to get some information if where condition is true. like: select USER_NAME,USER_EMAIL from table1 where Expiry_Date='2016-03- ...
Read more >How to Compare Dates in SQL
How to Compare Dates in SQL · Using Comparison Operators · Using the BETWEEN Clause · Using Comparison Operator with TimeStamp · Casting...
Read more >TIL: How to compare DateTime without the time part in SQL ...
To compare dates without the time part, don't use the DATEDIFF() or any other function on both sides of the comparison in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hmm not entirely true - adding the
[Neo4jDateTime]
attribute to a property which is a DateTime will serialize it as a Neo4j DateTime.The problem is how the
Where
knows this. Solution wise - I’m not sure how you would fix it - my gut feeling is that you either have a global setting which then treats all DateTime instances as one or the other. When you pass in a parameter it doesn’t know there is an attribute.I guess maybe an overload to
AddParam
which let’s you say it should be a Neo4j datetime would be the quickest route - does force you into a.WithParam
scenario thoughI don’t think this is a bug it’s just not yet supported. C# DateTime is serialized to a Neo4j string property in the format “2020-03-09T16:45:00.9199162+01:00” and back from string to C# DateTime. The neo4j temporal types and features which where introduced end of 2018 are not yet supported, see Issue #291