Cypher java date query - neo4j

I'm attempting to run a cypher query to return back nodes within a particular date range. When passing in the date object (Java) the query fails to return the correct nodes. I'm currently using the long date value (i.e. getTime()) which works as expected. This is great, but is there a way of just using the actual Date object?

Unfortunately neo4j has no support for storing actual date objects as properties. So, right now you have to pass in date.getTime() as cypher parameters.
We'll look into that.

It has been integrated in Neo4j 2.0, see timestamp.

Related

Is it possible to retrieve only the timestamp from a influxDb query

Is it possible to pass the timestamp retuned in influxDb query to another query.
Select max("value")
from "temp" where ("floor" = "1);
Output
time max
---- ---
2020-01-17T00:00:00Z 573.44
Is it possible to pass the time from the result to another query?
You cannot do this with InfluxQL,it is not possible to nest the queries in a way that could pass the time range of the inner query to the outer query. it's another matter if you were using Flux (new Query Language but still in BETA).
In Flux this is possible, because you can access time as a column, which you can then use to query your other measurements as required. You can also use JOIN to do more advanced operations like cross measurement calculations etc.

history attribute in neo4j

I was reading about Time-Based Versioned Graphs and came across the following example:
CREATE (s1:Shop{shop_id:1})
-[:STATE{from:1388534400000,to:9223372036854775807}]->
(ss1:ShopState{name:'General Store'})
My question: how do I calculate this date? from:1388534400000,to:9223372036854775807
Those two values are timestamps which in java are the number of milliseconds since the Epoch (1/1/1970) began. The second value is the maximum Long value, the end of Java time, a long way away.
There are ways in all languages for generating these values for specific dates (beware that some will be based on seconds), there is quite a handy list on this site.
If you are not working in any particular programming language and just want to enter queries then you can use an online date converter like this one.
You can also calculate timestamps in Cypher if you are working with dates that relate to Now somehow using the timestamp() function:
CREATE (s1:Shop{shop_id:1})
-[:STATE{from:timestamp(),to:9223372036854775807}]->
(ss1:ShopState{name:'General Store'})
IIUC to is just a Long.MAX_VALUE, and from can be a result of either calling timestamp() function via Cypher or setting the property with the value of System.currentTimeMills() via Java API.
Take a look at the example: http://console.neo4j.org/?id=43uoyt (Note that you can skip setting rel.to and use coalesce when querying instead).

JIRA REST API different datetime format

With JIRA REST API there is at least 2 ways to get an issue:
/jira/rest/api/2/issue/{issueIdOrKey}
/rest/api/2/search?jql
I use both of them in my project but they return a slightly different results for updated field for the same issue.
Get by key: 2014-07-18T17:53:02.594+0300
Search: 2014-07-18T17:53:02.000+0300
By some reason milliseconds in search response are not set. It looks like a bug for me, but maybe there is configuration setting or something?
PS: I have the latest JIRA version (6.2.6)
JQL search results are generally fetched directly from the Lucene index, which stores timestamps with only millisecond resolution, whereas fetching the actual issue gets the date directly from the jiraissue table in the database, which can have sub-millisecond resolution (at least depending on your configured database).
EDITED: I see that I misread the precision above: the timestamp returned by getting the issue returns only milliseconds (vs nanoseconds) and the JQL query returns only integer seconds (vs milliseconds), so the Lucene data type linked above is not relevant.
However, the answer is still the same: JQL gets the result from Lucene, while an issue fetch gets the value directly from the database. On further investigation of why the Lucene index is not returning milliseconds: in the JIRA source in BaseFieldIndexer.indexDateField, JIRA calls LuceneUtils.dateToString(date) to convert the created field into a value that is indexable by Lucene. The dateToString method explicitly converts the field into an integer number of seconds (lopping off any milliseconds in the process), and it then converts the number to a String representation for indexing purposes.
Odd! I checked this with a 6.2 instance and also got a difference:
JQL: updated: 2014-07-11T19:34:04.000-0500
Key: updated: 2014-07-11T19:34:04.768-0500
I bet the code that returns the list of issues from a search uses a different date formatter that clears the milliseconds, whereas the one that returns the data from a single issue doesn't do that. I don't know of any configuration setting that would affect that.
I recommend filing it as a minor bug at http://jira.atlassian.com/browse/JRA
Minor because any code that is checking something based on ms seems unwise.

Using Parse to query by time in iOS app

I have an app that needs to find objects posted to a class on parse based on the time they were created. I can get the time range in string format and I can change that to any format. How can I pull down certain ranges from the server that isn't just the entire day. Example: 2:15 until 4:30. I would need all objects created on the database between that time returned. Any ideas?
If I understand your question, you want certain objects that are created between specific time instances.( for example between 2:15 and 4:30). If I am right, then you can use the Parse query and its predicate whereKey : greaterThan: (PFQuery Class references. So the only thing that you have to do is giving the date format with hours and minutes. Then Parse will return the object based on your date predicate. Hope this helps.
Regards.

How to handle Dates as long numbers

I am trying to store Dates on my nodes on the database. I am loading data using webadmin and the csv importer, my problem is that data is saved as string and i need it to be long, i have found some methods to cast some types like toInt() but there is no equivalent for long type.
I have a node that contains two date fields, ArrivalDate and DepartureDate, it is a long number in the csv file but once the query is executed in neo4j the field is stored as a string. The problem is that i cannot make a query to compare Dates since they are strings, a sample query i want to run is like this:
match(p:Person)--(s:Stay)
where (s.ArrivalDate)<=634924360000000000 and s.DepartureDate>=634924360000000000)
So i would get all the people staying in that Date.
I have done some research, and also asked before here, maybe the question was not that good explained.
For references: i am using the webadmin to load csv files for the bulk load but then my app is in c# and i am using neo4jclient to work with the DB.
Neo4j 2.1 (which is about to release rather soon) has a Cypher command LOAD CSV. You can use toInt function to convert a string to a numeric value during import. Example:
LOAD CSV WITH HEADERS FROM 'file:/mnt/teamcity-work/42cff4ac2707ec23/target/community/cypher/docs/cypher-docs/target/docs/dev/ql/load-csv/csv-files/file.csv'
AS line
CREATE (:Artist { name: line.Name, year: toInt(line.Year)})

Resources