Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hello GKaiseril,
I'm having a bit of a problem in doing this Time calculation and was wondering if you could help?
I've used your 3 functions as 'Document Javascripts' and using a custom calculation script
" event.value = Mins2HrsMins( TimeDiff(this.getField("Field2 Time").value, this.getField("Field1 Time").value) ); " on the "TotHours" field but for some reason the "TotHours" field appears blank.
I've also tired using all 3 functions and the event.value as a custom calculation script but still get the same result.
Could you please let me know what I am doing wrong?
Thanks for you help in advance!
Ken!
Copy link to clipboard
Copied
Ken,
what is the foramt style of you time string?
The script is for "h:mm tt" like 9:00 am.
As to using web page JavaScirpt, you will need to adjsut it for the Acrobat JavaScirpt variation.
Copy link to clipboard
Copied
Hi GKaiseril,
Thanks a million for your prompt reply!!
Both the "Field2 Time" and the "Field1 Time" fields have the time format of "h:MM tt" format.
I am using your javascript script on the beginning of this page (which you did for Sonhia), but the field displaying the difference between the two times - "TotHours" - is blank.
I am using these scripts in a pdf form in Acrobat X (on a Mac) - Could that be an issue?
Thanks again!
Copy link to clipboard
Copied
No that should not be a problem.
Are the field names correct?
Are the field names spelled correctly?
Are the field names capitalized correctly?
Is JavaScript enabled in Acrobat?
Copy link to clipboard
Copied
Here is the script I am using:
function Time2Num(sTime, cFormat) {
// convert a date time string to seconds since the epoch date
var oTime = util.scand(cFormat, sTime); // date time object
var fTime = oTime.valueOf(); // time string to milliseconds
return Math.round(fTime / 1000); // return rounded seconds
}
function TimeDiff(sEnd, sStart) {
// compute difference in time within same day as minutes
var fEnd = 0; // default value if not data
var fStart = 0; // default value if not data
var cDateFormat = "m/d/yyyy "; // date format string
var sNowDate = util.printd(cDateFormat, new Date()); // get today's date as "m/d/yyyy'
var cDateTimeFormat = cDateFormat + "h:MM tt";
// compute difference if we have data
if(sEnd != "" & sStart != "") {
// get end time in minutes
var cDateTimeValue = sNowDate + sEnd; // start date time string
var fEnd = Time2Num(cDateTimeValue, cDateTimeFormat) / 60; // convert to seconds and divide by 60 sec
// get start time in minutes
var cDateTimeValue = sNowDate + sStart; // start date time string
var fStart = Time2Num(cDateTimeValue, cDateTimeFormat) / 60; // convert to seconds and divide by 60 sec
} // end if we have value
return fEnd - fStart; // compute and return the difference in minutes
} // end function
function Mins2HrsMins(fMinutes) {
// convert seconds into formatted string of hours:minutes
var cDisplayFormat = "%01.0f" + ":" + "%02.0f"; // format for returned value
var fHrs = Math.floor(fminutes / 60); // compute whole hours from the difference
var fMins = fMinutes % 60; // get minutes less than 1 hour form the difference
return util.printf(cDisplayFormat, fHrs, fMins); // format and return computed value
} // end function
var fDiff = TimeDiff(this.getField("Field2_Time").value, this.getField("Field1_Time").value)
event.value = Mins2HrsMins(fDiff); // format computed value
All the above code is in the "Calculate>Custom Calculate Script" of the "TotHours" field.
I have the Javascript Debugger enabled in Acrobat and when I enter the time in "Field2_Time" and hit the tab key I get this in the Debugger:
fminutes is not defined
31:Field:CalculateException in line 31 of function Mins2HrsMins, script Field:Calculate
Exception in line 37 of function top_level, script Field:Calculate
ReferenceError: fminutes is not defined
31:Field:Calculate
I hope this helps.
Thank you so much!
Copy link to clipboard
Copied
Hello GKaiseril,
As I red over the last reply, I figured where the error was and corrected it (fminutes should have been fMinutes on line 31)and it now works.
Thank very much for helping out with this.
Ken!
Copy link to clipboard
Copied
And do the form field names agree with your form fields in spelling, capitalization, and spaces in the name?
Have you looked at the JavaScript console for any errors?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied