InDesign - Insert Date

Ok... I feel really bad having to ask this question, but I cannot find an answer to it.

I am using Adobe InDesign CS2.

How do I get the current date in a text field?

I have a master page that needs to contain a text field showing the CURRENT date. I do not want to have to change this date every day, and certainly do not want to forget to change it and have the wrong day appear in the publication.

Thanks in advance!

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This really isn't a dumb question at all.  What IS dumb is that InDesign doesn't have an automatic date feature built in.  You have to have a script to do it.

There is a scripts palette.  There is also a Scripting Guide on the software CD.  It is also posted here:

1. What you would need to do is create a character style (called something like: autoDate) and apply that style to some text on a page.  
2. You need to save a script (i'll paste one below) with the extension .js in C:\Program Files\Adobe\Adobe InDesign CS2\Presets\Scripts
3. With that character style applied, double-click the script (using the scripts palette) with your document open and all instances of text assigned that style will be replaced with the current date

If you are on a MAC, I'll find out the specifics for that if you need them.

Below is a script that will make the date in this format ##/##/####

function LZ(n) {
 return (n > 9 ? n : '0' + n);

var d = new Date();
myDateString=(LZ(d.getMonth() + 1) + '/' +

app.findPreferences = null;
app.changePreferences = null;
myStyle = app.activeDocument.characterStyles.item("autoDate");
try {;
} catch (e) {
 // Style not defined in this doc so nothing to do
}"",false,false,myDateString,{appliedCharacterStyle: myStyle})

I hope this helps!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Thats pretty impressive! Could you please provide the Mac (OSX) version?

What I posted above might also work on a MAC, I just don't know enough about scripting and don't have a MAC to test it on.  But...

This is another thing I found is a script that is tied to an event (in this case, it adds a date when printing) and it would probably work on both a MAC and a PC.  This comes from someone using RougeSheep --

So, if you wrote a script to replace all instances of a character style named (say) CurrentDate with the current date and tied this to happen before a Print command was actually executed. That would do it.

A JavaScript to do this would look something like this:

//DESCRIPTION: Update Date in Active Document  /*
  Updates all instances of current date in a document to reflect the
  actual date when the script is run. Depends on character style named
  "CurrentDate" -- does nothing if document lacks said style.
 */ if (app.documents.length == 0) { exit() }
myDoc = app.activeDocument; //Global
var myStyle = myDoc.characterStyles.item("CurrentDate");
if (myStyle == null) { exit () } // If we get here, we have work to do
var myDate = getDateString(); // Use Find/Change across document to update date:
app.findPreferences = app.changePreferences = null;"", false, false, myDate, {appliedCharacterStyle:myStyle}); function getDateString() {
  var today = new Date();
  var myDateString = today.toLocaleDateString();
  myParts = myDateString.split(" 0");
  if (myParts.length != 1) {
  myDateString = myParts[0] + " " + myParts[1];
  return myDateString.slice(0,-5) + "," + myDateString.slice(-5);
To use the script, copy and paste to a text editor and save as a plain text file with an appropriate name in the form UpdateDate.jsx in the Scripts folder of the Presets folder of your InDesign CS2 folder (you could put it in a subfolder if you wish). Then to run the script, double-click its name in the Scripts palette.

If you want to work it with RogueSheep's InEventScript, follow their directions on how to connect this to the Print command. If you want the date in a different format, change the function to provide the format -- this might require some research.

But, the thing about the other script I posted... it works in InDesign CS.  Maybe someone on a MAC can try it for me?

OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

I will try at my earliest convenience, but I have a ton of stuff going on right now. Thanks though!

WallaceRAuthor Commented:
You rock ddhamm !!!
Wow, thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Graphics Software

From novice to tech pro — start learning today.