0

I'm new to Neo4j so maybe I'm just completely wrong on this, but I'll give it a try!

Our data is mostly composed by reservations, users and facilities stored as nodes.
I need both to count the total reservations that occurred in a specific time frame and the overall income (stored as reservation.income) in this timeframe.

I was thinking to overcome the problem by creating the date as a node, in this way I can assign a relationship [:PURCHASED_ON] to all the reservations that occurred on a specific date.

As far as I've understood, creating the date as a node could give me a few pros:

  • I could split the date from dd/mm/yyyy and store them as integer properties, in this way I could use mathematical operators such as > and <
  • I could create a label for the node representing each month as a word
  • It should be easier to sum() the income on a day or a month

Basicly, I was thinking about doing something like this

CREATE (d:Day {name:01/11/2016 day: TOINT(01), month: TOINT(11), year: TOINT(2016)}

I have seen that a possible solution could be to create a node for every year, every month (1-12) and every day (1-31), but I think that would just complicate terribly the architecture of my Graph since every reservation has an "insert_date" (the day it's created) and then the official "reservation_date" (the day it's due).

Am I onto something here or is it just a waste of time? Thanks!

Marco Rossi
  • 231
  • 1
  • 6
  • 1
    Possible duplicate of [How to handle dates in neo4j](http://stackoverflow.com/questions/29343767/how-to-handle-dates-in-neo4j) – stdob-- Dec 06 '16 at 14:56

2 Answers2

2

You may want to look at the GraphAware TimeTree library, as date handling is a complex thing, and this seems to be the logical conclusion of the direction you're going. The TimeTree also has support for finding events attached to your time tree between date ranges, at which point you can perform further operations (counting, summing of income, etc).

InverseFalcon
  • 29,576
  • 4
  • 38
  • 51
1

There are many date/time functions in the APOC plugin that you should take a look at.

As an example, you can use apoc.date.fields (incorrectly called by the obsolete name apoc.date.fieldsFormatted in the APOC doc) to get the year, month, day to put in your node:

WITH '01/11/2016' AS d
WITH apoc.date.fields(d, 'MM/dd/yyyy') AS f
CREATE (d:Day {name: d, day: f.days, month: f.month, year: f.years});

NOTE: The properties in the returned map have names that are oddly plural. I have submitted an issue requesting that the names be made singluar.

cybersam
  • 63,203
  • 6
  • 53
  • 76