Adobe has also posted a number of tutorials about time calculations.
In general, one converts the date string, yes, the visual representation of a date is a string and not a number, into a Date object. Then one can either add or subtract one day, either as a day unit or the number of milliseconds in a day, to get the next day or the previous day.
A sample script for display the 7 days before a given date:
var cStart = "07/02/2016"; // the starting date string;
var oStart = util.scand("mm/dd/yyyy", cStart); // convert date string to date object;
var oAdjsted; // date object for adjustment;
// count back 7 days and display each date's month and day;
for(var i = 6; i > -1; i--)
oAdjusted = new Date(oStart.getTime()); // reset adjusted date to start date;
oAdjusted.setDate(oAdjusted.getDate() - i); // adjust by -i days;
console.println((i + 1) + ": " + util.printd("dddd mmm dd", oAdjusted)); // display short month and 2 digit date;
} // loop back for next previous date;
To be able to fill in field's we would need the field names and what value should appear in the field name. Careful planning of the field names could make the script simpler since it is possible to cmpute field names or make the field name a computible variable.
How do I use the script? So the dates will calculate correctly and eliminate the 31st day where the month doesn't have 31 days? And where would I place the script? Is it a Custom Calculation? Or doc level, validate, etc?
It is an example of how to count down the dates and display the result for each incremental date. I would place this script in the "On Blur" action for the end date field. You can modify it so instead of printing to the console, you populate the field for each date. If your weekly interval includes dates in more than one year, you will also need to deal with the change in years.
The code has comments explaining what each line does.
Can you program n any language like Basic, Pascal, C?
Have you looked at any the Adobe provided tutorials?
If this the start of a time sheet you will be dealing with the Date object for at least 14 more fields. I would also create a number of document level scripts to perform the repeated blocks of code like converting a date string or date and time string into the Date object, and formatting scripts to convert minutes to display hours and minutes.
I tried and tried but I'm totally lost. All the explaining in the world doesn't help. I'm not at that level of understanding to apply what you're saying.
Hello Mr Kremer,
Thanks for responding. What I was getting at, is I just don't understand the script in the other post. It opens the console. I don't know what to do with the information there. I tried the script and cannot get it to work the way I want it to. So, after searching the Acrobat User forum I found this script which does work (to an extent).
It calculates the days as I would like, but it also calculates the month and year. That part I don't want or need. I just want the Day. Take a look, can this script be modified to return just the day in the text field? I placed this script in each Day field (Sun thru Sat) as a Custom Calculation. I just know I'm getting closer.
event.value=util.printd("mm/dd/yyyy",new Date(new Date(this.getField("Sat").value).getTime()-86400000))
I don't know what the number (86400000) means or what it is referring to. It originally had a "+" in front of it. I changed it to a "-" to suite my needs. (Good guess, huh). Anyway, what do you think?
Here's a link to a sample form that demonstrates how you can do this: http://acroscript.net/pdf/demos/populateWeek.pdf
The script is in the Validate event of the date input field. Note that the day fields use a particular naming convention which allows some code simplification, so you'd have to use a similar pattern.
Thank you Mr Johnson. That's perfect. More perfect than my ex-wife's hairdo.