Strengthening on the Cypher Basics guides, this guide talks about the brand new temporary time versions lead for the Neo4j step 3.4. Up on completing this informative guide, you should be able to create, compare, and structure these philosophy.
Just be regularly chart databases rules in addition to property graph model. This article is actually an extension of basics chatted about from the previous Cypher sections. You need to be regularly Suits, Create/Update/Remove, and you may Filtering principles prior to strolling through this guide.
Creating and upgrading beliefs
Let us start with performing particular nodes which have a Datetime property. We can do this by carrying out next Cypher ask:
UNWIND [ , , ] AS articleProperties CREATE (article:Article ) SET article.created = articleProperties.created, article.datePublished = articleProperties.datePublished, article.readingTime = duration(articleProperties.readingTime)
- the latest created house is a good DateTime sorts of equal to brand new datetime at that time the brand new inquire is actually carried out.
- the latest date home is a romantic date sort of equal to the new time during the time the fresh new inquire was executed.
- the new readingTime are a period particular 3 minutes 30 seconds.
We made a decision to publish the content next week in place of today, so we want to make one transform. Whenever we want to would another Time type playing with an excellent supported format, we could do it utilizing the following the query:
Fits (article:Post ) Place blog post.datePublished = date("2019-09-30")
But what when we need to create a night out together types of situated with the an enthusiastic unsupported format? To accomplish this we are going to use a features in the APOC collection so you can parse the sequence.
The following inquire parses an unsupported file format for the a good millisecond mainly based timestamp, produces a great Datetime away from you to definitely timestamp, and produces a night out together from one Datetime :
With apoc.day.parse("Sun, ", "ms", "EEE, dd MMMM yyyy") Because ms Matches (article:Post ) Place blog post.datePublished = date(datetime())
We can use this exact same method to inform the fresh written possessions. The one thing we have to alter is that we do not need convert the fresh new Datetime sorts of so you’re able to a night out together :
That have apoc.date.parse(" ", "ms", "dd MMMM yyyy HH:mm:ss") As ms Fits (article:Post ) Place post.composed = datetime()
Possibly we in addition to choose that the training big date is basically supposed getting one minute more than what we should originally envision. We can inform the new readingTime possessions to your adopting the inquire:
Matches (article:Blog post ) Place article.readingTime = article.readingTime + duration()
Formatting philosophy
Now we would like to produce an inquiry to return all of our blog post. We could do that because of the doing another inquire:
Fits (article:Article) Get back blog post.identity As title, post.composed Given that written, blog post.datePublished Given that datePublished, article.readingTime Because the readingTime
If we must structure these types of thinking we can fool around with temporary qualities on APOC library. The second query forms each of the temporary sizes into the significantly more amicable platforms:
Matches (article:Article) Get back post.title Due to the fact label, apoc.temporal.format(article.composed, "dd MMMM yyyy HH:mm") Since created, apoc.temporal.format(article.datePublished,"dd MMMM yyyy") Because datePublished, apoc.temporal.format(blog post.readingTime, "mm:ss") As readingTime
Comparing and you will filtering thinking
Fits (article:Article) Where article.datePublished = date() Come back post.term While the title, post.created Once the written, blog post.datePublished As datePublished, blog post.readingTime Because readingTime
How about when we want to see all of the articles authored from inside the ? We could possibly generate another ask to do so:
Fits (article:Article) Where article.datePublished = date() Return post.label Given that identity, post.created Because the authored, article.datePublished Since the datePublished, post.readingTime Because readingTime
This doesn’t check best – how about the fresh new Cypher Principles II article that has been penned for the next ? The problem we have here is one big date() productivity 2019-06-01 , very we’re just in search of stuff had written for the first .
Matches (article:Article) Where day() > article.datePublished >= date() Come back article.name As the label, article.authored Given that composed, blog post.datePublished Once the artikel datePublished, blog post.readingTime Given that readingTime