Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateTime comparison in WHERE condition

See original GitHub issue

Hello, 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
        public DateTime Arrival { get; set; }

        public DateTime Departure { get; set; }

…and the following query:

DateTime arrival = DateTime.Parse("2019-03-22T10:00:00");
var query = client.Cypher
    .Where((Something thing) => thing.Arrival > arrival)

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:open
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

cskardoncommented, Mar 11, 2020

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 though

Clooney24commented, Mar 11, 2020

I 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found