Reputation: 687
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
Upvotes: 1
Views: 616
Reputation: 18022
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"
Upvotes: 2
Reputation: 517
Two notes:
You should use a format like HH:mm that means that you need to specify 9:30 as 09:30.
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
Upvotes: 2