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

Date question re day of week

jenawyn
Registered: Apr 1 2011
Posts: 12
Answered

I am using this at document level to autofill current date on form
 
// Set field value to current system date
getField("todaysDate").value = util.printd("dd mmmm yyyy", new Date());
 
The question is no matter what I try I cant get it to put the day of the week in.
 
I would like it to display (dddd-dd-mmmm-yyyy)
Wednesday 14th April 2011
 
Thanks

My Product Information:
Acrobat Pro 9.4.2, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
This:

util.printd("dddd dd mmmm yyyy", new Date());


Generated this:

Wednesday 06 April 2011
jenawyn
Registered: Apr 1 2011
Posts: 12
Thanks works
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Then try:

function CardinalDate(oDate) {
var short_date = util.printd("d", oDate);

// build value for cardinal short date
switch(short_date) {
case "1":
case "11":
case "21":
case "31":
short_date += "st";
break;

case "2":
case "22":
short_date += "nd";
break;

case "3":
case "23":
short_date += "rd";
break;

default:
short_date += "th";
break;
} // end of switch

return short_date;
} // end CardinalDate function

function FormalDate(oDate, sLiteral) {
var sFormalDate = "";
if((sLiteral == "") | (sLiteral == " ") | (typeof sLiteral == "undefined"))
sFormalDate = util.printd("dddd", oDate) + " " + CardinalDate(oDate) + " " + util.printd("mmmm yyyy", oDate);
else
sFormalDate = util.printd("dddd", oDate) + " " + CardinalDate(oDate) + " " + sLiteral + " " + util.printd("mmmm yyyy", oDate);
return sFormalDate;
}

var oDate = new Date();
event.value = FormalDate(oDate);

Sample output:

Thursday 7th April 2011

You could optional add "of" or 'day of' to the field value by adding the optional second parameter to the function call for FormalDate:

event.value = FormalDate(oDate, "of");
Thursday 7th of April 2011

event.value = FormalDate(oDate, "day of");
Thursday 7th day of April 2011

You can place the functions as document level functions and you could then reuse this code as needed within a form or easily transfer the code for the functions to other forms.

George Kaiser