Neo4J: How SET a property from String to Date?










0















I have the following nodes with this properties:



 MATCH (a:Personname:'Raf', birthDay:'05/07/1992'),
(b:Personname:'Mary', birthDay:'10/08/1991'),
(c:Personname:'Luke', birthDay:'11/01/1995')


How could I set the birthDay from String format to Date format?
And How could I order my nodes considering birthDay and have its rank?










share|improve this question




























    0















    I have the following nodes with this properties:



     MATCH (a:Personname:'Raf', birthDay:'05/07/1992'),
    (b:Personname:'Mary', birthDay:'10/08/1991'),
    (c:Personname:'Luke', birthDay:'11/01/1995')


    How could I set the birthDay from String format to Date format?
    And How could I order my nodes considering birthDay and have its rank?










    share|improve this question


























      0












      0








      0








      I have the following nodes with this properties:



       MATCH (a:Personname:'Raf', birthDay:'05/07/1992'),
      (b:Personname:'Mary', birthDay:'10/08/1991'),
      (c:Personname:'Luke', birthDay:'11/01/1995')


      How could I set the birthDay from String format to Date format?
      And How could I order my nodes considering birthDay and have its rank?










      share|improve this question
















      I have the following nodes with this properties:



       MATCH (a:Personname:'Raf', birthDay:'05/07/1992'),
      (b:Personname:'Mary', birthDay:'10/08/1991'),
      (c:Personname:'Luke', birthDay:'11/01/1995')


      How could I set the birthDay from String format to Date format?
      And How could I order my nodes considering birthDay and have its rank?







      date neo4j set order cypher






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 9:56







      raf

















      asked Nov 14 '18 at 9:36









      rafraf

      406




      406






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The first operation to do is to split the text of the birthday to distinguished parts :



          RETURN split('05/07/1992', '/') AS parts


          will return an array



          ["05", "07", "1992"]


          The second operation is to create a date object :



          WITH split('05/07/1992', '/') AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])


          The problem is that day, month and year expect integer values, not strings :



          WITH [x IN split('05/07/1992', '/') | toInteger(x)] AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])

          ╒════════════════════════════════════════════════════════╕
          │"date(day: parts[0], month: parts[1], year: parts[2])"│
          ╞════════════════════════════════════════════════════════╡
          │"1992-07-05" │
          └────────────────────────────────────────────────────────┘


          Now for the second question, how to order the nodes by birthday and have its rank ?



          Well, you could order by a timestamp instead, however as you can see in this documentation reference about the date type, it doesn't have the epochMillis on it, so you can rather use datetime instead.



          Full flow :



          // Create Persons
          CREATE (a:Personname:'Raf', birthDay:'05/07/1992'),
          (b:Personname:'Mary', birthDay:'10/08/1991'),
          (c:Personname:'Luke', birthDay:'11/01/1995')

          // Set datetime as dob property

          MATCH (p:Person)
          WITH p, [x IN split(p.birthDay, "/") | toInteger(x)] AS parts
          SET p.dob = datetime(day: parts[0], month: parts[1], year: parts[2])

          // Return younger persons

          MATCH (p:Person) RETURN p ORDER BY p.dob.epochMillis DESC





          share|improve this answer























          • I have a big DB how could I solve this problem: Maximum call stack size exceeded

            – raf
            Nov 14 '18 at 12:04












          • @raf I suggest to open a new question with the query and code (in case doing it from app code )

            – Christophe Willemsen
            Nov 14 '18 at 13:13










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296991%2fneo4j-how-set-a-property-from-string-to-date%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The first operation to do is to split the text of the birthday to distinguished parts :



          RETURN split('05/07/1992', '/') AS parts


          will return an array



          ["05", "07", "1992"]


          The second operation is to create a date object :



          WITH split('05/07/1992', '/') AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])


          The problem is that day, month and year expect integer values, not strings :



          WITH [x IN split('05/07/1992', '/') | toInteger(x)] AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])

          ╒════════════════════════════════════════════════════════╕
          │"date(day: parts[0], month: parts[1], year: parts[2])"│
          ╞════════════════════════════════════════════════════════╡
          │"1992-07-05" │
          └────────────────────────────────────────────────────────┘


          Now for the second question, how to order the nodes by birthday and have its rank ?



          Well, you could order by a timestamp instead, however as you can see in this documentation reference about the date type, it doesn't have the epochMillis on it, so you can rather use datetime instead.



          Full flow :



          // Create Persons
          CREATE (a:Personname:'Raf', birthDay:'05/07/1992'),
          (b:Personname:'Mary', birthDay:'10/08/1991'),
          (c:Personname:'Luke', birthDay:'11/01/1995')

          // Set datetime as dob property

          MATCH (p:Person)
          WITH p, [x IN split(p.birthDay, "/") | toInteger(x)] AS parts
          SET p.dob = datetime(day: parts[0], month: parts[1], year: parts[2])

          // Return younger persons

          MATCH (p:Person) RETURN p ORDER BY p.dob.epochMillis DESC





          share|improve this answer























          • I have a big DB how could I solve this problem: Maximum call stack size exceeded

            – raf
            Nov 14 '18 at 12:04












          • @raf I suggest to open a new question with the query and code (in case doing it from app code )

            – Christophe Willemsen
            Nov 14 '18 at 13:13















          1














          The first operation to do is to split the text of the birthday to distinguished parts :



          RETURN split('05/07/1992', '/') AS parts


          will return an array



          ["05", "07", "1992"]


          The second operation is to create a date object :



          WITH split('05/07/1992', '/') AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])


          The problem is that day, month and year expect integer values, not strings :



          WITH [x IN split('05/07/1992', '/') | toInteger(x)] AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])

          ╒════════════════════════════════════════════════════════╕
          │"date(day: parts[0], month: parts[1], year: parts[2])"│
          ╞════════════════════════════════════════════════════════╡
          │"1992-07-05" │
          └────────────────────────────────────────────────────────┘


          Now for the second question, how to order the nodes by birthday and have its rank ?



          Well, you could order by a timestamp instead, however as you can see in this documentation reference about the date type, it doesn't have the epochMillis on it, so you can rather use datetime instead.



          Full flow :



          // Create Persons
          CREATE (a:Personname:'Raf', birthDay:'05/07/1992'),
          (b:Personname:'Mary', birthDay:'10/08/1991'),
          (c:Personname:'Luke', birthDay:'11/01/1995')

          // Set datetime as dob property

          MATCH (p:Person)
          WITH p, [x IN split(p.birthDay, "/") | toInteger(x)] AS parts
          SET p.dob = datetime(day: parts[0], month: parts[1], year: parts[2])

          // Return younger persons

          MATCH (p:Person) RETURN p ORDER BY p.dob.epochMillis DESC





          share|improve this answer























          • I have a big DB how could I solve this problem: Maximum call stack size exceeded

            – raf
            Nov 14 '18 at 12:04












          • @raf I suggest to open a new question with the query and code (in case doing it from app code )

            – Christophe Willemsen
            Nov 14 '18 at 13:13













          1












          1








          1







          The first operation to do is to split the text of the birthday to distinguished parts :



          RETURN split('05/07/1992', '/') AS parts


          will return an array



          ["05", "07", "1992"]


          The second operation is to create a date object :



          WITH split('05/07/1992', '/') AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])


          The problem is that day, month and year expect integer values, not strings :



          WITH [x IN split('05/07/1992', '/') | toInteger(x)] AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])

          ╒════════════════════════════════════════════════════════╕
          │"date(day: parts[0], month: parts[1], year: parts[2])"│
          ╞════════════════════════════════════════════════════════╡
          │"1992-07-05" │
          └────────────────────────────────────────────────────────┘


          Now for the second question, how to order the nodes by birthday and have its rank ?



          Well, you could order by a timestamp instead, however as you can see in this documentation reference about the date type, it doesn't have the epochMillis on it, so you can rather use datetime instead.



          Full flow :



          // Create Persons
          CREATE (a:Personname:'Raf', birthDay:'05/07/1992'),
          (b:Personname:'Mary', birthDay:'10/08/1991'),
          (c:Personname:'Luke', birthDay:'11/01/1995')

          // Set datetime as dob property

          MATCH (p:Person)
          WITH p, [x IN split(p.birthDay, "/") | toInteger(x)] AS parts
          SET p.dob = datetime(day: parts[0], month: parts[1], year: parts[2])

          // Return younger persons

          MATCH (p:Person) RETURN p ORDER BY p.dob.epochMillis DESC





          share|improve this answer













          The first operation to do is to split the text of the birthday to distinguished parts :



          RETURN split('05/07/1992', '/') AS parts


          will return an array



          ["05", "07", "1992"]


          The second operation is to create a date object :



          WITH split('05/07/1992', '/') AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])


          The problem is that day, month and year expect integer values, not strings :



          WITH [x IN split('05/07/1992', '/') | toInteger(x)] AS parts
          RETURN date(day: parts[0], month: parts[1], year: parts[2])

          ╒════════════════════════════════════════════════════════╕
          │"date(day: parts[0], month: parts[1], year: parts[2])"│
          ╞════════════════════════════════════════════════════════╡
          │"1992-07-05" │
          └────────────────────────────────────────────────────────┘


          Now for the second question, how to order the nodes by birthday and have its rank ?



          Well, you could order by a timestamp instead, however as you can see in this documentation reference about the date type, it doesn't have the epochMillis on it, so you can rather use datetime instead.



          Full flow :



          // Create Persons
          CREATE (a:Personname:'Raf', birthDay:'05/07/1992'),
          (b:Personname:'Mary', birthDay:'10/08/1991'),
          (c:Personname:'Luke', birthDay:'11/01/1995')

          // Set datetime as dob property

          MATCH (p:Person)
          WITH p, [x IN split(p.birthDay, "/") | toInteger(x)] AS parts
          SET p.dob = datetime(day: parts[0], month: parts[1], year: parts[2])

          // Return younger persons

          MATCH (p:Person) RETURN p ORDER BY p.dob.epochMillis DESC






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 11:29









          Christophe WillemsenChristophe Willemsen

          15.3k21929




          15.3k21929












          • I have a big DB how could I solve this problem: Maximum call stack size exceeded

            – raf
            Nov 14 '18 at 12:04












          • @raf I suggest to open a new question with the query and code (in case doing it from app code )

            – Christophe Willemsen
            Nov 14 '18 at 13:13

















          • I have a big DB how could I solve this problem: Maximum call stack size exceeded

            – raf
            Nov 14 '18 at 12:04












          • @raf I suggest to open a new question with the query and code (in case doing it from app code )

            – Christophe Willemsen
            Nov 14 '18 at 13:13
















          I have a big DB how could I solve this problem: Maximum call stack size exceeded

          – raf
          Nov 14 '18 at 12:04






          I have a big DB how could I solve this problem: Maximum call stack size exceeded

          – raf
          Nov 14 '18 at 12:04














          @raf I suggest to open a new question with the query and code (in case doing it from app code )

          – Christophe Willemsen
          Nov 14 '18 at 13:13





          @raf I suggest to open a new question with the query and code (in case doing it from app code )

          – Christophe Willemsen
          Nov 14 '18 at 13:13

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296991%2fneo4j-how-set-a-property-from-string-to-date%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線