Forum Moderators: open
var date1 = this.getField("Date1").value;
var date2 = this.getField("Date2").value;
function period(date1, date2)
{
var period = (date1-date2);
return period/1000/3600/168;
}
It don't seem to work, any help will be appreciated.
Thanks
Acrobat JavaScript Debugger Functions Version 7.0
Acrobat EScript Built-in Functions Version 7.0
Acrobat Annotations / Collaboration Built-in Functions Version 7.0
Acrobat Annotations / Collaboration Built-in Wizard Functions Version 7.0
Acrobat Multimedia Version 7.0
Acrobat SOAP 7.0
TypeError: this.getField("Date1") has no properties
1:Field:Calculate
Your help will beappreciated.
Thanks again.
function getField(prime)
{
return document.getElementById(prime);
}
var date1 = getField("Date1").value;
var date2 = getField("Date2").value;
function period(a, b)
{
a=parseInt(date1, 10);
b=parseInt(date2, 10);
var period = (a-b);
return period/1000/3600/168;
}
getField("period").value=period(date1, date2);
function findField(prime)
{
return document.getElementById(prime);
}
var date1 = findField("Date1").value;
var date2 = findField("Date2").value;
function period(a, b)
{
a=parseInt(date1, 10);
b=parseInt(date2, 10);
var period = (a-b);
return period/1000/3600/168;
}
findField("period").value=period(date1, date2);
<script type="text/javascript">
function showDiff(f) {
var date1 = new Date(f.d1y.value, f.d1m.value - 1, f.d1d.value);
var date2 = new Date(f.d2y.value, f.d2m.value - 1, f.d2d.value);
f.diff.value = Math.floor((date2.getTime() - date1.getTime()) / 604800000 );
}
</script>
<form>
Date 1: day<input type="text" name="d1d" size="2">
month<input type="text" name="d1m" size="2">
year<input type="text" name="d1y" size="4"><br>
Date 2: day<input type="text" name="d2d" size="2">
month<input type="text" name="d2m" size="2">
year<input type="text" name="d2y" size="4"><br>
<input type="button" value="show difference" onclick="showDiff(this.form)"><br>
<br>
Difference, in weeks: <input type="text" name="diff" size="4">
</form>
The function showDiff() creates two date objects using the input in the form fields:
var date2 = new Date(year, month, day);
For some reason January is considered to be month #0, so we need to substract 1 from the user's input.
The method date.getTime() returns the number of milliseconds between midnight, 1/1/1970 (GMT) and the date: an integer, on which we can finally perform calculations.
The method Math.floor(x) rounds the value of x down; maybe you prefer Math.round or Math.ceil.
Please note that all necessary input validation was omitted from the script.
HTH
Yes, that is what I am hoping for, a time difference in weeks from dates that are inserted into an Acrobat form.
Thanks for your efforts.
I guess that I will just have to do it manually.
Thanks again.
Date arithmetic
It is often useful to do arithmetic on dates to determine things like the time interval between
two dates or what the date will be several days or weeks in the future. The JavaScript Date
object provides several ways to do this. The simplest and possibly most easily understood
method is by manipulating dates in terms of their numeric representation. Internally, JavaScript
dates are stored as the number of milliseconds (one thousand milliseconds is one whole
second) since a fixed date and time. This number can be retrieved through the valueOf method
of the Date object. The Date constructor allows the construction of a new date from this
number.
/* Example of date arithmetic. */
/* Create a Date object with a definite date. */
var d1 = util.scand("mm/dd/yy", "4/11/76");
/* Create a date object containing the current date. */
var d2 = new Date();
/* Number of seconds difference. */
var diff = (d2.valueOf() - d1.valueOf()) / 1000;
/* Print some interesting stuff to the console. */
console.println("It has been " + diff + " seconds since 4/11/1976");
console.println("It has been " + diff / 60 + " minutes since 4/11/1976");
console.println("It has been " + (diff / 60) / 60 + " hours since 4/11/1976");
console.println("It has been " +
((diff / 60) / 60) / 24 + " days since 4/11/1976");
console.println("It has been " +
(((diff / 60) / 60) / 24) / 365 + " years since 4/11/1976");
The output of this script would look something like:
It has been 718329600 seconds since 4/11/1976
It has been 11972160 minutes since 4/11/1976
It has been 199536 hours since 4/11/1976
It has been 8314 days since 4/11/1976
It has been 22.7780821917808 years since 4/11/1976
Tried this
/* Example of date arithmetic. */
/* Create a Date object with a definite date. */
var date1 = util.scand("mm/dd/yy", "4/11/76");
/* Create a date object containing the current date. */
var date2 = new Date();
/* Number of days difference. */
var diff = (date2.valueOf() - date1.valueOf()) / (1000*3600*168);
/* Print some interesting stuff to the console. */
console.println("It has been " + diff + " weeks since 4/11/1976");
but no string is printed. Any help?
var Today=AFParseDateEx(getField("Today").value, "mdy");
var LMP=AFParseDateEx(getField("LMP").value, "mdy");
var diff=Today-LMP;
event.value = (diff/86400000/7);
Math.floor(event.value);
Instead of returning the largest whole number less than or equal to the specified number it gives the closest whole number(if the part following the decimal is 5 or greater it gives the next whole number).
Please check whether the script does what you think it does:
var Today=AFParseDateEx(getField("Today").value, "mdy");
var LMP=AFParseDateEx(getField("LMP").value, "mdy");
var diff=Today-LMP;
console.println("diff = " + diff);
event.value = (diff/86400000/7);
console.println("event.value = " + event.value);
var floored = Math.floor(event.value);
console.println("floored = " + floored);
This is what I have:
var today=AFParseDateEx(getField("Today").value, "mdy");
var add=getField("AddWeeks").value*1000 * 60 * 60 * 24 * 7;
var newdate = today+add;
/* set the event value to the calculated date */
this.getField("NewDate").value = util.printd("mdy", newdate) ;
There seems to be a problem with it.