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

Calculating time between from date field with some exceptions

Petronella
Registered: Jan 23 2008
Posts: 2

"Lahtopaiva_ja_aika_1" and "Saapumispaiva_ja_aika_1" are in date format (m/d/yyyy HH:MM)
I would need a field "Korvattavat_tunnit_1" to be in number format (calculating time
(in hours) between those taking few exceptions into account)
I have this in acrobat 8 form
I have only wrote this script and not sure where to go from here
event.value = this.getField("Lahtopaiva_ja_aika_1").value + this.getField("Saapumispaiva_ja_aika_1")

\\change date into time

\\if choice in combo-box is either mon-fri

\\and if time is between 24:00-07:00, how many hours from that is between this

\\and if time is between 18:00-23:59, how many hours from that is between this,
\\or is there easier way to take into account only hours between 18:00-07:00?

\\and if choice in combo-box is sat-sun, all the hours are taken into account from
Lahtopaiva_ja_aika_1 until Saapumispaiva_ja_aika_1

\\these hours are in Lahtopaiva_ja_aika_1
\\and Saapumispaiva_ja_aika_1 and the summ of those is called Korvattavat_tunnit_1 field.

I really appreciate for any help!

My Product Information:
Acrobat Pro 8.0, Windows
pddesigner
Registered: Jul 9 2006
Posts: 858
This solution is not exactly what you want to do but will give you a start. You need to find a way to use this in a combo box that adds or subtracts the results.

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 this:

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

The following example shows the addition of dates.

/* Example of date arithmetic. */
/* Create a date object containing the current date. */
var d1 = new Date();
/* num contains the numeric representation of the current date. */
var num = d1.valueOf();
/* Add thirteen days to today’s date, in milliseconds. */
/* 1000 ms/sec, 60 sec/min, 60 min/hour, 24 hours/day, 13 days */
num += 1000 * 60 * 60 * 24 * 13;
/* Create our new date, 13 days ahead of the current date. */
var d2 = new Date(num);
/* Print out the current date and our new date using util.printd */
console.println("It is currently: "
+ util.printd("mm/dd/yyyy", d1));
console.println("In 13 days, it will be: "
+ util.printd("mm/dd/yyyy", d2));

The output of this script would look something like this:

It is currently: 01/15/1999
In 13 days, it will be: 01/28/1999

My favorite quote - "Success is the ability to go from one failure to another with no loss of enthusiasm.