• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can InDesign return the week day to a given date?

Community Beginner ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

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

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 27, 2017 Feb 27, 2017

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.ge

...

Votes

Translate

Translate
Community Expert ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

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

InDesign Scripting

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

"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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

Tuesday has the same name as Thursday in German?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

Eagle eye.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 14, 2019 Jan 14, 2019

Copy link to clipboard

Copied

Old thread, hello again …


I  have started with Jongware´s script and I ended up with exactly what I needed in regular text frames when I highlight the according text – works like a charm, thanks again. One thing I am trying to achieve now is: I have a table, the first column contains the dates. I want to manually select the column and then make the script loop through the rows … and I really don´t get my head around it. I know I´ll have to address the proper object, but I don´t get it at which point to insert: I have selected the column, how do I tell the script to read the text (date) in every cell of that selection (column)?

This is the working part for reading and replacing the date:

date = new Date(app.selection[0].contents)

datestr = ('0'+date.getDate()).slice(-2)+' '+["SO", "MO", "DI", "MI", "DO", "FR", "SA"][date.getDay()]  // put a leading zero to dates 1-9

if (confirm(datestr)) { // yes or cancel

  app.selection[0].contents = datestr

}

(Also, I haven´t figured out yet how to display code properly. Sorry for that.)

I assume I´ll have to address the ".contents"-bit and tell it what object it´s looking for and then cycle through that, but how?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

LATEST

Did it!

After my first attempt with "Tackling Tables through Scripting" didn´t work, I could make the script loop through the rows. For any future reference, this is how the code snippet looks now:

for (i=0; i<table.rows.length; i++)

{

if (table.rows.cells[0].texts[0].length == 0) // condition 1: if cell empty

continue; // skip

date = new Date(table.rows.cells[0].contents) // else

datestr = ["SO", "MO", "DI", "MI", "DO", "FR", "SA"][date.getDay()]+' '+('0'+date.getDate()).slice(-2)  // put a leading 0 to dates 1-9

table.rows.cells[0].contents = datestr;

if (table.rows.cells[0].contents == table.rows[i-1].cells[0].contents) // condition 2: turn duplicate dates transparent

table.rows.cells[0].texts[0].fillColor = "None";

}

}

Thanks to all participants in this thread pointing me towards scripting and specially to [Jongware]​!

Edit: Told the script to skip empty cells and put a second condition to turn duplicate cell contents (=dates) transparent

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines