3 Replies Latest reply on Jan 12, 2012 4:03 PM by John Hawkinson

    Modifying auto-date format


      Hello guys,


      I'm using ID CS3 on a XP machine in Spanish.


      I've been fiddling with this script to stamp today's date in an Indy document.


      It works very good, and I got it to even insert tomorrow's date.


      The resulting date is in this format: jueves, enero 12, 2012.


      I am trying now to change it to this format (this is in Spanish): jueves, 12 de enero de 2012.


      This is the script:


      function dayMonthYear(date) {

      // returns dayName, monthName date, year

      // PLUS ONE DAY


      var myDateString = date.toLocaleDateString();

      myParts = myDateString.split(" 0");

      if (myParts.length != 1) {

      myDateString = myParts[0] + " " + myParts[1];


      return myDateString.slice(0,-5) + " de" + myDateString.slice(-5);



      Remember, ID and the OS are in Spanish, and according to date.toLocaleDateString() the script should return the date in this format: "jueves, 12 de enero de 2012". Why does it return "jueves, enero 12, 2012"?


      I am not very good at scripting, but.. Can anybody help me change the script so it returns the date in my desired format?


      Thanks a lot in advance.

        • 1. Re: Modifying auto-date format
          John Hawkinson Level 5

          Did you try printing out the values? Or single-stepping?


          I think the issue is you have misunderstood how Array.split works:


          "jueves, enero 12, 2012".split(" 0").join("\n")

          Result: jueves, enero 12, 2012

          "jueves, enero 12, 2012".split(" ").join("\n")

          Result: jueves,





          Your split always fails because the string " 0"  never appears.

          • 2. Re: Modifying auto-date format
            gjmendozar Level 1

            Thanks for your reply John,


            As the matter of fact, I actually do not know how Array.split works, since I am not a programmer, just a designer


            As you can see, I am starting from a script already written by a contributor in this forum some time ago.


            Googling around I saw that date.toLocaleDateString() in this Windows machine in Spanish should return the date in this format: Jueves, 12 de Enero de 2012 (proven in a web browser). But using this script I get the format mentioned above: jueves, enero 12, 2012. This script is obviously written for English based machines.


            I also read something about using the split function to delete the leading zero on single-numbered days. But as I said, I do not understand that very good.


            So my issue here is about the date format. What do I have to change to get my correct local date format?


            Again, thanks for replying.

            • 3. Re: Modifying auto-date format
              John Hawkinson Level 5

              What do you have to do? Well, it is tricky. It is tricky to get right. The better answer is "Don't."


              But if you must, you'll have to be quite clear.

              Exactly what do you want to do to the returend date string?


              Specify it very clearly. Something like:


                Split it up into space-seperated words.

                Insert "de" between the 3rd and 4th word and the 7th and 8th word.

                Swap the 3rd and 5th words.

                Capitalize the first word.

                Put it all back together.


              I can imagine many ways to poentially get what you want and as non-Spanish speaker, I am not sure what weird exceptions there are.


              The split function divides a string on the specified character. Such as splitting a sentence into words by calling .split(" "), which splits on spaces.

              See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Split for a good reference with some examples.