These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Day of the week

The X
Registered: Mar 27 2011
Posts: 24

Is there a JS fonction that can test a date field and provide what day of the week(monday, tuesday, etc) it corresponds to ?

My Product Information:
Acrobat Pro 10.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Yes, getDay()
See here for more info: http://www.w3schools.com/jsref/jsref_obj_date.asp

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

The X
Registered: Mar 27 2011
Posts: 24
Thanks for the quick response. That's exactly what I'm looking for. But I always face the same issue. I'm new to JS and I'm a quick self-learner but I don't understand how to use simple lines of code in Acrobat. All the examples I can find on the internet, are "raw" JS examples and I need to convert them for the acrobat API. I tried many ways by removing parts I don't think I need, use it in many events (onblur, calculate, validate, etc) but can't get nothing out of it except "undefined". I need a good and free "JS for acrobat tutorial". I want to finally be able to figure it out by myself.

I'm getting good with the "if" logic and can create my own codes. I want to get as confidant as I already am with MS Excel.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
There are several good tutorials online for working in JS in Acrobat. Many on them on this site...
If you post your code here, you would probably get help in achieving what you described.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

The X
Registered: Mar 27 2011
Posts: 24
var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

document.write("Today is " + weekday[d.getDay()]);

That's the code I found on the internet. Now, date field is named "SUR_ENT_ORIGIN" and the day field is named "JOUR". I want the day to display automatically upon entering the date. Once corrected, where do I paste the code?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Once you get your date string converted to a date object, you can use the "util.printd" method to get various variations of the day of the week.

The 'getDay()' method returns the zero based day of the week with Sunday as zero and if you want the spelled out day of the week, then you need some extra code.

Using the 'util.printd' method you can get the shror or long day names.

var sDate = "03/31/2010"; // date string
var oDate = util.scand("mm/dd/yyyy", String(sDate)); // convert to date object
var nJSDay = oDate.getDay(); // JS Day of the week
var sMsg = "JS day of the week: " + nJSDay + '\n';
var sUPDDayShort = util.printd("ddd", oDate); // short day of the week
sMsg += "util.printd short day of the week: " + sUPDDayShort + '\n';
var sUPDDayLong = util.printd("dddd", oDate); // long cay of the week
sMsg += "util.printd long day of the week: " + sUPDDayLong;
app.alert(sMsg, 3, 0, "Day of the Week");

Acrobat JS is not always the same as Web page JS. There is no "document.write" statement.

There are many ways to get a value into a field, but Acrobat JS usually does not show an update to a field until a script completes and many scripts do not run or complete until a the focus changes to another field.

You could use the 'On Blur' action of the "SUR_ENT_ORIGIN" field to set the value of the "JOUR" field. Or your you could use a custom calculation script for the "JOUR" field to compute the day of the week from the "SUR_ENT_ORIGIN" field value.

You might want to look at MDC Java Script Reference ver 1.5 and JavaScript for Acrobat references for more information.The above script produces output like:

JS day of the week: 3
util.printd short day of the week: Wed
util.printd long day of the week: Wednesday

George Kaiser