Answered
Thom ParkerCorrect answer
Community Expert
Jul 3, 2023 7:12 PM UTC
The full script will need to be a calculation script in the "Week End Date" field.
Remove the date formatting from this field, and make it ReadOnly. Formatting is only needed when dates are entered manually.
The input date will need to be created using the "util.scand" function. And the Output will need to be formatted using util.printd. Like this (same script just using scand and printd to handle the date formatting)
var strWorkDate = this.getField("Work Date").value;
if(strWorkDate != "")
{
var dtStart = util.scand("m/d/yyyy",strWorkDate);
// Sunday is 0, Monday is 1, etc.
var nDayOfWeek = dtStart .getDay();
var dtEndOfWeek = null;
if(nDayOfWeek == 0)
{// Today is Sunday, so today is the end of the week
dtEndOfWeek = dtStart ;
}
else
{// Find number of days until next sunday, then add to current date
nOffsetToSunday = 7-nDayOfWeek;
nSundayDateTime = dtStart.setDate(dtStart.getDate() + nOffsetToSunday);
dtEndOfWeek = new Date(nSundayDateTime);
}
event.value = util.printd("m/d/yyyy",dtEndOfWeek);
}
else
event.value = "";
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
