Strengthening into Cypher Basics books, this article talks about the temporary big date versions put inside the Neo4j 3.cuatro. On finishing this informative guide, you should be capable manage, contrast, and you will format such viewpoints.
Just be always graph databases concepts and also the property graph model. This article are an extension of your principles discussed from the prior Cypher sections. You should be regularly Fits, Create/Update/Remove, and Filtering principles ahead of taking walks through this publication.
Carrying out and you may updating philosophy
Let us start with creating particular nodes that have a Datetime assets. We are able to do that from the doing the second Cypher inquire:
UNWIND [ < title:>, < title:>, < title:> ] AS articleProperties CREATE (article:Article ) SET article.created = articleProperties.created, article.datePublished = articleProperties.datePublished, article.readingTime = duration(articleProperties.readingTime)
- the fresh composed home is an excellent DateTime form of equivalent to the latest datetime at the time the inquire are performed.
- the latest time house is a romantic date sorts of comparable to the newest day at the time new ask are executed.
- the fresh readingTime are a duration types of three full minutes 30 seconds.
We now have decided to publish the content next week unlike today, so we need to make that transform. Whenever we have to would a different Go out particular playing with good offered style, we can exercise with the following inquire:
Matches (article:Article ) Set article.datePublished = date("2019-09-30")
But what whenever we need certainly to perform a night out together form of based on the an unsupported format? To accomplish this we're going to explore a purpose on APOC library so you're able to parse the sequence.
Next query parses an enthusiastic unsupported data format into the an excellent millisecond created timestamp, produces an excellent Datetime regarding one timestamp, right after which produces a date from one Datetime :
That have apoc.time.parse("Sun, ", "ms", "EEE, dd MMMM yyyy") Because ms Matches (article:Article ) Place post.datePublished = date(datetime())
We are able to utilize this same way of inform the latest created property. The single thing we must change is that do not need move new Datetime style of in order to a romantic date :
Which have apoc.day.parse(" ", "ms", "dd MMMM yyyy HH:mm:ss") Since the ms Match (article:Article ) Put article.composed = datetime()
Possibly we in addition to choose that the studying day is actually heading getting an additional over whatever you originally believe. We can improve the brand new readingTime possessions to the after the ask:
Match (article:Blog post ) Lay blog post.readingTime = post.readingTime + duration()
Formatting values
Today we would like to make a query to return our very own article. We are able to do this of the executing another inquire:
Meets (article:Article) Go back post.term As the title, blog post.written Because created, blog post.datePublished Due to the fact datePublished, post.readingTime Since readingTime
Whenever we should style these types of beliefs we can play with temporal attributes on the APOC collection. The second inquire types all the temporal brands into the a great deal more amicable formats:
Meets (article:Article) Come back blog post.identity While the title, apoc.temporal.format(post.created, "dd MMMM yyyy HH:mm") Since written, apoc.temporary.format(article.datePublished,"dd MMMM yyyy") Because the datePublished, apoc.temporary.format(article.readingTime, "mm:ss") Because readingTime
Comparing and you can filtering opinions
Matches (article:Article) Where blog post.datePublished = date() Return article.term Because term, post.created Because the created, post.datePublished As datePublished, blog post.readingTime While the readingTime
Think about when we should find all the articles had written in ? We might make another query to take action:
Meets (article:Article) Where post.datePublished = date() Get back article.name Since name, article.authored Due to the fact composed, blog post.datePublished While the datePublished, post.readingTime Just like the readingTime
It doesn't look correct - what about the fresh Cypher Basics II article which had been authored toward 2nd ? The situation i have let me reveal you to big date() production 2019-06-01 , very we're just wanting content typed towards 1st .
Match (article:Article) Where date() > blog post.datePublished >= date() Go back post.name Because identity, blog post.written As the composed, post.datePublished While the datePublished, mexikansk kvinnor blog post.readingTime Because readingTime