1

I created some user nodes with some value-time:

CREATE (u1:User {name:'user 1', pickUpTime:'10:10', dropOffTime:'10:35'})

I wonder what is a good way (format) to store time, because when i do this kind of queries

MATCH (u:User) RETURN u.name AS name, u.pickUpTime AS pickTime Order by pickTime desc

I got this as result

name    pickTime
user 3  9:30
user 2  10:20
user 1  10:10

And i need to get an ordered result:

 name   pickTime
 user 3  9:30
 user 1 10:10
 user 2 10:20

Any suggestions? Thanks in advance

marhg
  • 659
  • 1
  • 17
  • 30

2 Answers2

2

Two notes:

  1. You should use a format like HH:mm that means that you need to specify 9:30 as 09:30.

  2. Also in the previous case you need to specify "order by pickTime asc" and not desc if you would like to obtain the order you desire

  • With Neo4j 2.3. and an index on that field you can also use range search on the field as well as `starts with` to find for instance all `09:` 9 o'clock matches. – Michael Hunger Nov 01 '15 at 17:45
2

Time is a much trickier thing that it first appears, usually because time often refers back to a timezone, a date, or something else.

Many people will store the epoch time that they get from java via System.getCurrentTimeMillis(). They'll then convert it to whatever they need later on.

Other people will store the number of minutes after midnight if they're just looking for a relative time of day (i.e. 2:30PM)

Another option is to use Java Date objects as values. These are richer and allow you to express a timezone, calendar concepts, etc.

Storing them as strings is definitely a losing proposition for most use cases. Storing as something like a long integer permits direct comparison, but also requires that you convert something like an epoch time to a string that you really want, like "9:30"

Community
  • 1
  • 1
FrobberOfBits
  • 17,634
  • 4
  • 52
  • 86
  • 1
    there is also the timestamp() function in cypher – Michael Hunger Nov 01 '15 at 17:44
  • @FrobberOfBits thank you, i think storing the number of minutes after midnight is a good option. So i think i will consider it if i want to perform calculation btw times – marhg Nov 03 '15 at 14:41