13 Replies Latest reply on Feb 27, 2017 6:03 AM by M. Schilde

    Can InDesign return the week day to a given date?

    M. Schilde

      Hello all,

       

      I am working regularly on event brochures with 200++ events which are cross-referenced several times throughout the document. Often times, in the original data that I get from clients, week days get confused. For example, the script says: Friday, Feb 25th 2017. Unfortunately though, that would have been a Saturday …

       

      I was wondering, if I could make InDesign take the date like a variable? I would write down every date like this: DD.MM.YYYY (since I am in Germany that would be our format). Through magic/witch craft, InDesign could recognize the variable and handle it according to my character-/paragraph-/ or GREP-styles. InDesign would then generate the output: "Samstag, 25.02.17", or "SA 25", or "25. Februar 2017", or "02/25/17", or however I specify the date to be displayed in that table/paragraph/document.

       

      Since week days can be calculated, it should be quite easy? But I haven´t found any solution yet.

       

      If this doesn´t exist or work at all: Do you know any script which will scan a text and – if it recognizes a date – will display the according week day in a tool tip?

       

      Thanks a lot for any input!

       

      Kind regards,

      Martin

        • 1. Re: Can InDesign return the week day to a given date?
          Steve Werner Adobe Community Professional & MVP

          If you don't get an answer here, ask in the InDesign Scripting forum:

           

          InDesign Scripting

          • 2. Re: Can InDesign return the week day to a given date?
            Sandee Cohen Adobe Community Professional

            I can do it by inserting an anchored text frame that is linked to an external file or a Content Grabber source.

             

            But the results may not be what you want as the date doesn't break across the lines of body text.

             

            So it depends on your layout.

             

            Show an example of the various layouts and I'll let you know if my technique would work. And then how to do it.

            • 3. Re: Can InDesign return the week day to a given date?
              M. Schilde Level 1

              Wow, thanks for your kind offer Sandee,

              I´ll attach two screen shots to show my layouts.

               

              This is (last year´s) table layout with 200+ single dates, each date having it´s own cell:

              Bildschirmfoto 2017-02-27 um 10.32.16.png

               

              And this is another instance of date inside a normal text frame:

              Bildschirmfoto 2017-02-27 um 10.33.07.png

               

              My idea is to just write down the proper date like DD.MM.YYYY and let ID convert it into the format needed: in the table only into "SA 20", inside the text frame to "Samstag, 12. November 2016", mainly so the week day is added automatically.

               

              Did I get that right: with your solution I would have to provide an additional file with the correct dates for ID to look after?

               

              Curios to see if your idea is applicable

              • 4. Re: Can InDesign return the week day to a given date?
                TᴀW Adobe Community Professional & MVP

                This is very scriptable, but there's nothing built-in InDesign to do it.

                 

                For instance, this 1-line script will allow you to type in a date (in many formats, though not separated by periods [12.5.87 won't work]; try using slashes [12/5/87]). It will display the date in your local machines current formatting (so if that is set to show the day of the week, you will see that).

                 

                alert((new Date(prompt())).toLocaleString());

                 

                A lot of customization is possible for the output, of course. And it's not a large step from here to looping through all dates in your document and substituting the correct day...

                 

                Ariel

                2 people found this helpful
                • 5. Re: Can InDesign return the week day to a given date?
                  M. Schilde Level 1

                  Nice.

                  Then it would be the last step before going to print, right? Because it would replace any string that matches [M/D/YY]? Dates would not be handled like cross-references/hyperlinks inside the document, that update themselves whenever a page moves?

                   

                  Would that script replace every string inside the document with the same output format that is defined through how i set up my computer? Say, in my example I have the table output, which should differ from the output in regular text frames. Both have different paragraph styles – could that be addressed?

                   

                  Martin

                  • 6. Re: Can InDesign return the week day to a given date?
                    TᴀW Adobe Community Professional & MVP

                    "Then it would be the last step before going to print, right? Because it would replace any string that matches [M/D/YY]?"

                    I guess so.

                     

                    "Dates would not be handled like cross-references/hyperlinks inside the document, that update themselves whenever a page moves?"

                    No. But this makes it sound like you're looking for something different. You could set up perhaps, a running header with the name of the day, on each page. Then, when you move an event to a different page, the day would get picked up by the running-header variable. It depends exactly what  you're after.

                     

                    "Would that script replace every string inside the document with the same output format that is defined through how i set up my computer? Say, in my example I have the table output, which should differ from the output in regular text frames. Both have different paragraph styles – could that be addressed?"

                     

                    Anything is possible. It depends what you would want.

                     

                    I can't offer to write a complete script here for free, but you could (a) ask in the scripting forum -- there are some people there who are getting their feet wet and might be interested in taking this on as a challenge; or (b) contact me through a private message for a quote; or (c) best option: take the plunge yourself and try and put something together in the scripting department (it's not as hard as it looks!) :-)

                     

                    Ariel

                     

                     

                     

                    1 person found this helpful
                    • 7. Re: Can InDesign return the week day to a given date?
                      [Jongware] Most Valuable Participant

                      Automatically searching for dates and replacing everything it finds may not be safe. Here is a short snippet of JavaScript that will replace just a selected date – you can see how to rebuild a date string, so you can adjust it to taste.

                       

                      date = new Date(app.selection[0].contents)
                      datestr = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Dienstag", "Freitag", "Samstag"][date.getDay()]
                      datestr += ', '
                      datestr += ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"][date.getMonth()]
                      datestr += ' '+ date.getDate()+', '+date.getFullYear()
                      alert(datestr);
                      app.selection[0].contents = datestr
                      

                       

                      (You can safely remove the 'alert' line, so it will immediately effect the selected text.)

                       

                      date.PNG

                       

                      (Edit: huh - the image uses 'getYear', which returns the year from 1900 on, and hence the "117". So, better use "getFullYear" there. I changed it in the script.)

                      1 person found this helpful
                      • 8. Re: Can InDesign return the week day to a given date?
                        M. Schilde Level 1

                        Thanks Ariel,

                         

                        the cross-reference comparison was more about pointing out my idea of having the date handled like a variable throughout the whole process. So, if the date receives an update, the output would automatically generate the new week day. But I understand, that´s not possible.

                         

                        I will definitely look into scripting that thing!

                        • 9. Re: Can InDesign return the week day to a given date?
                          M. Schilde Level 1

                          Holy! That´s gold! Thank you Jongware!

                           

                          This is what comes closest to what I am looking for. This way, at least I can validate every date the moment I insert the text into the document.

                           

                          I´ll take that as a starting point and see how I can make ID output the information that I need. I assume I´m going to use a different script for every kind of display. I´ll dig deep

                           

                          Thanks a lot!

                          • 10. Re: Can InDesign return the week day to a given date?
                            TᴀW Adobe Community Professional & MVP

                            Tuesday has the same name as Thursday in German?

                            1 person found this helpful
                            • 11. Re: Can InDesign return the week day to a given date?
                              M. Schilde Level 1

                              Eagle eye.

                               

                              Actually no, it would have to be "Dienstag" for "Tuesday" and "Donnerstag" for "Thursday".

                              • 12. Re: Can InDesign return the week day to a given date?
                                [Jongware] Most Valuable Participant

                                wôôt ...

                                 

                                I wasn't sure I could write out the correct Namen for all the Tagen from memory, so I looked it up on the interwebz. After all, it's only one quick copy-and-paste ...

                                 

                                It goes to show, you cannot believe anything you find on the net

                                • 13. Re: Can InDesign return the week day to a given date?
                                  M. Schilde Level 1

                                  You think it´s worth it to make this a full feature request?

                                   

                                  I cannot imagine it would be in anyone´s interest to have a wrong week day next to a date. Maybe a general approach in terms of having a date put down like a place holder/variable, i.e. through a date picker, and then defining the actual output through character/paragraph/GREP style would come in handy, not only to myself, but also others? (Word offers to display the current date in different formats?)

                                   

                                  Cheers