0

I have some nodes in a collection with a Date Time:

enter image description here

I query this using the C# cypher client thus:

 GraphClient _client = new GraphClient(new Uri(url));
 DateTime dt;
 _client.Cypher
     .Match("(e:LineStop)")
    .Where((LineStop e) => e.AddedToDataWarehouse == false && e.TimeCreated >= dt)
    .AndWhere((LineStop e) => e.Duration >0)
    .Return<LineStop>("e")
    .Results;

This works.

How can I do the same thing using the standard web based Neo4j Graph client? I can't seem to get the syntax to work at all.

enter image description here

All of the existing Q&As seem to talk about structuring the data differently to be more graph like and use shortestPath. I can't do this. The data already exists. I did not design this system nor do I have the abillity to change it.

I was told by the person that did design this system (a contractor who is no longer with the company) that Neo4j now supports dates(as opposed to stringfying them). On some level it must, or else how does the C# code work, right?

Community
  • 1
  • 1
Liam
  • 27,717
  • 28
  • 128
  • 190

3 Answers3

1

It looks like you need a string split function:

match (l.LineStop)-[:Creates]->(ls.LineStop) 
where l.Name = 'M-E' AND
      split(ls.TimeCreated, 'T')[0] = '2017-03-17'
return l, ls limit 100
stdob--
  • 28,222
  • 5
  • 58
  • 73
  • I want a greater than or equal to though, not just that day but every day subsequently as well. TBH Ideally I want a `BETWEEN` type syntax – Liam Mar 17 '17 at 16:54
1

In this case a STARTS WITH predicate should do the trick:

match (l.LineStop)-[:Creates]->(ls.LineStop) 
where l.Name = 'M-E' AND ls.TimeCreated starts with '2017-03-17'
return l, ls limit 100
InverseFalcon
  • 29,576
  • 4
  • 38
  • 51
  • I want a greater than or equal to though, not just that day but every day subsequently as well. TBH Ideally I want a `BETWEEN` type syntax – Liam Mar 17 '17 at 16:54
  • Are you referring to the span of TimeCreated + the duration? If so, what time unit does the duration represent, and is it numeric or a string? If not, are you passing in two date strings and wanting the LineStop's TimeCreated to be between them? – InverseFalcon Mar 17 '17 at 17:30
1

The C# code is treating the Dates as strings, if you look at what is being sent over the wire (using Fiddler), you'll see the JSON has it all escaped. Importantly, it's treating it as ISO format, which is sortable. If you chose to store them using US/UK format, you'd quickly find the comparison doesn't work.

The comparison is being done by Neo4j - example cypher showing the situation you have is here:

MATCH (n) RETURN 
CASE WHEN ("2017-03-19T08:12:17.9680461+00:00" > "2017-03-20T08:12:17.9680461+00:00") = true
THEN "TRUE"
ELSE "FALSE"
END

If you put that into your browser, you'll get FALSE.

Your query isn't working as you are doing a string comparison and '2017-03-17' is not the same as the actual string you have created. Of the two options below - the adding of a property is the best route - and doesn't involve changing the structure of the graph, but obviously depends on the ability to set a property on the node.

If you can't add extra properties to the objects

  • To do a 'Between' style approach - You have to pass in a fully defined DateTimeOffset string example: 2017-03-19T08:12:17.9680461+00:00

  • To do an equality comparison (with just the date specificied) Use STARTS WITH as @InverseFalcon said

This is awkward as a full DTOffset string is long and unwieldy :/

If you can add a property

I would add a Ticks version of the DateTime properties, i.e. have a property called TimeCreatedTicks which is simply the .Ticks property of the TimeCreated property. This is my general route for storing Dates.

For manual querying this is still a pain as you need to know the Ticks for a given date - and that (for me at least) normally involves going to LinqPad and running new DateTime(2017,3,17).Ticks.Dump()

Community
  • 1
  • 1
Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42
  • My dates are stored as a `DateTimeOffset` so the full syntax should do it, though your right it is unwieldy. TBH I'm surprised that a piece of technology in 2017 does not support a date data type. It's a bit silly having to deal with this at such a low level myself, but there you go. Thanks! – Liam Mar 20 '17 at 09:50