• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help needed for Time Calc Java Script

New Here ,
Nov 18, 2008 Nov 18, 2008

Copy link to clipboard

Copied

Hi,
I am trying to create a timesheet in PDF and have hit a speed bump. Is there anyone there who could provide me with a script that calculated the difference between 2 times? (Field2 time)-(Feild 1 Time) = Duration.I am desperate and have tried everything.
I proccess the payroll for a company and all of the 500 or so timesheets that I received each fortnight are paper copies and I am pulling my hair out. I need to use Adobe forms (We have Adobe Pro 9 and I am using the XML forms, not live cycle) as the serach engine that we use for emails cannot search on excel documents.

I have no Java script experience and I am getting completely lost in the subject. Any help would be greatly appreciated.

Thanks anyone who can help at all.
-Sohnia

Views

19.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 19, 2008 Nov 19, 2008

Copy link to clipboard

Copied

Using Acrobat forms JavaScript, the following script will compute the time difference in hours and minutes within the same day:

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

The 3 functions can be placed as a document level functions. One only needs to call the "TimeDiff(sEnd, sStart)" with the end and start time strings to get the difference in minutes between the start and end times. This value can then be further processed to summ other differences. The "Sec2HrsMins()" will format a minutes value to hours and minutes if any additional processing is done.

Of one can use the following event script to compute the difference and format the result with one line of code:

event.value = Mins2HrsMins( TimeDiff(this.getField("Field2 Time").value, this.getField("Field1 Time").value) );

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 19, 2008 Nov 19, 2008

Copy link to clipboard

Copied

Thankyou Geo Kaiser, this worked perfectly. I would not have been able to get this without your help. You cant imagine how much time you have saved me. I am very greatful.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2008 Nov 24, 2008

Copy link to clipboard

Copied

Hello again, I have tried modifying this script slightly to sum the value of 2 or more times to get a timesheet total. I have gotten it to work but it is very long I am still using the TimeDiff variance as I dont know what variance code I should be using. (I am using a field with a zero value and using the Field 2 Zero Value and repeating in the script to add the daily times up).

Am I correct in assuming that I should use the same script but just a different variance coding to sum times? Could anyone please let me know what code I should use?
I need to keep the size of this timesheet as small as possible otherwise our IT area will not let me use it. Any help would be appreciated.
Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2008 Nov 25, 2008

Copy link to clipboard

Copied

If you place the functions as a document level script, "Advance => Document Processing => Document JavaScirpts...", then one does not need to repeat the funciton code for each call of the function by each field.

You code for each period would be similar to:

var fDiff = TimeDiff(this.getField("Field2 Time").value, this.getField("Field1 Time").value)
event.value = Mins2HrsMins(fDiff); // format computed value

And you would only need to change the field names as required.

To get the total for a series of fields one could use a custom calculation script similar to:

var fDiff = TimeDiff(this.getField("Field2 Time").value, this.getField("Field1 Time").value); // get first pair of times
fDiff += TimeDiff(this.getField("Field4 Time").value, this.getField("Field3 Time").value) // add next pair of times
fDiff += TimeDiff(this.getField("Field6 Time").value, this.getField("Field5 Time").value) // add next pair of times
fDiff += TimeDiff(this.getField("Field8 Time").value, this.getField("Field7 Time").value) // add next pair of times
fDiff += TimeDiff(this.getField("Field1- Time").value, this.getField("Field9 Time").value) // add last pair of times
event.value = Mins2HrsMins(fDiff); // format computed value

Or one could even fill in each day's time while computing the sum.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2012 Jun 11, 2012

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2012 Jun 11, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2012 Jun 11, 2012

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2012 Jun 11, 2012

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2012 Jun 11, 2012

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2012 Jun 11, 2012

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2012 Jun 11, 2012

Copy link to clipboard

Copied

LATEST

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009

Copy link to clipboard

Copied

hi friend here example for time calulation start and end time example..<br />just copy and paste then run it ur browser.<br /><br /><HTML><br /><script language="JavaScript"><br /><!--<br /><br />var h1 = 1;<br />var h2 = 2;<br />var days = 0;<br />var m1 = 1;<br />var m2 = 2;<br />var am1 = 1;<br />var am2 = 2;<br />function findtime(h1,h2,days,m1,m2,am1,am2)<br />{<br />var answer = "why";<br />var mdiff = 1;<br />var hdiff = 2;<br />pdays = parseInt(days);<br />ph1 = parseInt(h1);<br />ph2 = parseInt(h2);<br />pm1 = parseInt(m1);<br />pm2 = parseInt(m2);<br />if(am1 == 2 & ph1 < 12) ph1 = ph1 + 12;<br />if(am2 == 2 & ph2 < 12) ph2 = ph2 + 12;<br />if(am1 == 1 & ph1 == 12) ph1 = 24;<br />if(am2 == 1 & ph2 == 12) ph2 = 24;<br />if(am1 == 2 & am2 == 1 & ph2 < 24) ph2 = ph2 + 24;<br />if(am1 == am2 & ph1 > ph2) ph2 = ph2 + 24;<br />if(pm2 < pm1){<br />pm2 = pm2 + 60;<br />ph2 = ph2 - 1;<br />}<br />mdiff = pm2 - pm1;<br />hdiff = (ph2 - ph1) + (pdays * 24);<br />if(hdiff == 0) answer = mdiff + ' minutes';<br />else if(hdiff == 1) answer = '1 hour and ' + mdiff + ' minutes'<br />else answer = hdiff + ' hours and ' + mdiff + ' minutes'<br />return answer<br />}<br /><br />//--><br /></script><br /></HEAD><br /><br /><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br /><BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080><br /><br /><div align="center"><table width="950" border="0" cellpadding="0" bgcolor="#899194" cellspacing="0"><br /><br /> <br /><tr><td valign="middle" width="33%"><br /><br /><center><br /><form><br /><TD WIDTH=80%><br /><center><br /><TABLE ALIGN=MIDDLE BORDER=5 CELLPADDING=5><br /><TR BGCOLOR=#FFFFFF><br /><!--ROW 1--><br /><TD WIDTH=80%><br /><center><br /><TABLE ALIGN=MIDDLE BORDER=5 CELLPADDING=5><br /><TR BGCOLOR="#B6D4D2"><br /><!--ROW 1--><br /><td colspan=4><br /><center>Time Between Times Calculations - Multiple Days</center><br /><br /></td><br /></tr><br /><TR BGCOLOR="#B6D4D2"><br /><TD align="center" colspan=4><br />Required Data Entry<br /></td><br /></tr><br /><tr><br /><td align="center">Start / End</td><br /><td align="center">Hour</td><br /><td align="center">Minute</td><br /><td align="center">AM / PM</td><br /></tr><br /><br /><td align="center">Start time</td><br /><td align="center"><input type="text" name="hour1" size="5"></td><br /><td align="center"><input type="text" name="minute1" size="5"></td><br /><td align="center"><select name="period1"><br /><option value="1">AM<br /><option value="2">PM<br /></select><br /></td><br /></tr><br /><tr><br /><td colspan="3">    Add Complete Interim Days</td><td align="center"><input type="text" name="adays" size="5" value="0"></td><br /></tr><br /><tr><br /><td align="center">Start / End</td><br /><br /><td align="center">Hour</td><br /><td align="center">Minute</td><br /><td align="center">AM / PM</td><br /></tr><br /><td align="center">End time</td><br /><td align="center"><input type="text" name="hour2" size="5"></td><br /><td align="center"><input type="text" name="minute2" size="5"></td><br /><td align="center"><select name="period2"><br /><option value="1">AM<br /><option value="2">PM<br /></select><br /></td><br /></tr><br /><br /><tr><br /><td align="center" colspan=4 BGCOLOR="#B6D4D2"><br /><input type="button" value="Calculate" <br />onclick="h1=form.hour1.value;<br />h2=form.hour2.value;<br />m1=form.minute1.value;<br />m2=form.minute2.value;<br />days=form.adays.value;<br />am1=form.period1.options[period1.selectedIndex].value;<br />am2=form.period2.options[period2.selectedIndex].value;<br />if(h1 < 0 | h1 > 12) alert('Your start hour is not valid');<br />else if(h2 < 0 | h2 > 12) alert('Your end hour is not valid');<br />else if(m1 < 0 | m1 > 59) alert('Your start minute is not valid');<br />else if(m2 < 0 | m2 > 59) alert('Your end minute is not valid');<br />else form.answer.value=findtime(h1,h2,days,m1,m2,am1,am2);"><br />   <br /><input type="reset" value="Clear Values"><br /><br /></td><br /></tr><br /><TR BGCOLOR="#B6D4D2"><br /><TD align="center" colspan=4><br />Calculated Results<br /></td><br /></tr><br /><br /><tr><br /><td align="center" colspan="4"><br />Time Difference <input type="text" name="answer" size="40"><br /><tr><td>vino7tech@gmail.com</td></tr><br /></td><br /></tr><br /></table><br /></form><br /></td><br /></tr><br /></table><br /><br /></center><br /></td><br /></tr><br /></table><br /></center><br /><br /></TD><br /></TR><br /></TABLE><br /></BODY> <br /></HTML>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009

Copy link to clipboard

Copied

hi friend here example for time calulation start and end time example..<br />just copy and paste then run it ur browser.<br /><br /><HTML><br /><script language="JavaScript"><br /><!--<br /><br />var h1 = 1;<br />var h2 = 2;<br />var days = 0;<br />var m1 = 1;<br />var m2 = 2;<br />var am1 = 1;<br />var am2 = 2;<br />function findtime(h1,h2,days,m1,m2,am1,am2)<br />{<br />var answer = "why";<br />var mdiff = 1;<br />var hdiff = 2;<br />pdays = parseInt(days);<br />ph1 = parseInt(h1);<br />ph2 = parseInt(h2);<br />pm1 = parseInt(m1);<br />pm2 = parseInt(m2);<br />if(am1 == 2 & ph1 < 12) ph1 = ph1 + 12;<br />if(am2 == 2 & ph2 < 12) ph2 = ph2 + 12;<br />if(am1 == 1 & ph1 == 12) ph1 = 24;<br />if(am2 == 1 & ph2 == 12) ph2 = 24;<br />if(am1 == 2 & am2 == 1 & ph2 < 24) ph2 = ph2 + 24;<br />if(am1 == am2 & ph1 > ph2) ph2 = ph2 + 24;<br />if(pm2 < pm1){<br />pm2 = pm2 + 60;<br />ph2 = ph2 - 1;<br />}<br />mdiff = pm2 - pm1;<br />hdiff = (ph2 - ph1) + (pdays * 24);<br />if(hdiff == 0) answer = mdiff + ' minutes';<br />else if(hdiff == 1) answer = '1 hour and ' + mdiff + ' minutes'<br />else answer = hdiff + ' hours and ' + mdiff + ' minutes'<br />return answer<br />}<br /><br />//--><br /></script><br /></HEAD><br /><br /><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br /><BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080><br /><br /><div align="center"><table width="950" border="0" cellpadding="0" bgcolor="#899194" cellspacing="0"><br /><br /> <br /><tr><td valign="middle" width="33%"><br /><br /><center><br /><form><br /><TD WIDTH=80%><br /><center><br /><TABLE ALIGN=MIDDLE BORDER=5 CELLPADDING=5><br /><TR BGCOLOR=#FFFFFF><br /><!--ROW 1--><br /><TD WIDTH=80%><br /><center><br /><TABLE ALIGN=MIDDLE BORDER=5 CELLPADDING=5><br /><TR BGCOLOR="#B6D4D2"><br /><!--ROW 1--><br /><td colspan=4><br /><center>Time Between Times Calculations - Multiple Days</center><br /><br /></td><br /></tr><br /><TR BGCOLOR="#B6D4D2"><br /><TD align="center" colspan=4><br />Required Data Entry<br /></td><br /></tr><br /><tr><br /><td align="center">Start / End</td><br /><td align="center">Hour</td><br /><td align="center">Minute</td><br /><td align="center">AM / PM</td><br /></tr><br /><br /><td align="center">Start time</td><br /><td align="center"><input type="text" name="hour1" size="5"></td><br /><td align="center"><input type="text" name="minute1" size="5"></td><br /><td align="center"><select name="period1"><br /><option value="1">AM<br /><option value="2">PM<br /></select><br /></td><br /></tr><br /><tr><br /><td colspan="3">    Add Complete Interim Days</td><td align="center"><input type="text" name="adays" size="5" value="0"></td><br /></tr><br /><tr><br /><td align="center">Start / End</td><br /><br /><td align="center">Hour</td><br /><td align="center">Minute</td><br /><td align="center">AM / PM</td><br /></tr><br /><td align="center">End time</td><br /><td align="center"><input type="text" name="hour2" size="5"></td><br /><td align="center"><input type="text" name="minute2" size="5"></td><br /><td align="center"><select name="period2"><br /><option value="1">AM<br /><option value="2">PM<br /></select><br /></td><br /></tr><br /><br /><tr><br /><td align="center" colspan=4 BGCOLOR="#B6D4D2"><br /><input type="button" value="Calculate" <br />onclick="h1=form.hour1.value;<br />h2=form.hour2.value;<br />m1=form.minute1.value;<br />m2=form.minute2.value;<br />days=form.adays.value;<br />am1=form.period1.options[period1.selectedIndex].value;<br />am2=form.period2.options[period2.selectedIndex].value;<br />if(h1 < 0 | h1 > 12) alert('Your start hour is not valid');<br />else if(h2 < 0 | h2 > 12) alert('Your end hour is not valid');<br />else if(m1 < 0 | m1 > 59) alert('Your start minute is not valid');<br />else if(m2 < 0 | m2 > 59) alert('Your end minute is not valid');<br />else form.answer.value=findtime(h1,h2,days,m1,m2,am1,am2);"><br />   <br /><input type="reset" value="Clear Values"><br /><br /></td><br /></tr><br /><TR BGCOLOR="#B6D4D2"><br /><TD align="center" colspan=4><br />Calculated Results<br /></td><br /></tr><br /><br /><tr><br /><td align="center" colspan="4"><br />Time Difference <input type="text" name="answer" size="40"><br /><tr><td>vino7tech@gmail.com</td></tr><br /></td><br /></tr><br /></table><br /></form><br /></td><br /></tr><br /></table><br /><br /></center><br /></td><br /></tr><br /></table><br /></center><br /><br /></TD><br /></TR><br /></TABLE><br /></BODY> <br /></HTML>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009

Copy link to clipboard

Copied

<pre><br /><HTML><br /><script language="JavaScript"><br /><!--<br /><br />var h1 = 1;<br />var h2 = 2;<br />var days = 0;<br />var m1 = 1;<br />var m2 = 2;<br />var am1 = 1;<br />var am2 = 2;<br />function findtime(h1,h2,days,m1,m2,am1,am2)<br />{<br />var answer = "why";<br />var mdiff = 1;<br />var hdiff = 2;<br />pdays = parseInt(days);<br />ph1 = parseInt(h1);<br />ph2 = parseInt(h2);<br />pm1 = parseInt(m1);<br />pm2 = parseInt(m2);<br />if(am1 == 2 & ph1 < 12) ph1 = ph1 + 12;<br />if(am2 == 2 & ph2 < 12) ph2 = ph2 + 12;<br />if(am1 == 1 & ph1 == 12) ph1 = 24;<br />if(am2 == 1 & ph2 == 12) ph2 = 24;<br />if(am1 == 2 & am2 == 1 & ph2 < 24) ph2 = ph2 + 24;<br />if(am1 == am2 & ph1 > ph2) ph2 = ph2 + 24;<br />if(pm2 < pm1){<br />pm2 = pm2 + 60;<br />ph2 = ph2 - 1;<br />}<br />mdiff = pm2 - pm1;<br />hdiff = (ph2 - ph1) + (pdays * 24);<br />if(hdiff == 0) answer = mdiff + ' minutes';<br />else if(hdiff == 1) answer = '1 hour and ' + mdiff + ' minutes'<br />else answer = hdiff + ' hours and ' + mdiff + ' minutes'<br />return answer<br />}<br /><br />//--><br /></script><br /></HEAD><br /><br /><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br /><BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080><br /><br /><div align="center"><table width="950" border="0" cellpadding="0" bgcolor="#899194" cellspacing="0"><br /><br /> <br /><tr><td valign="middle" width="33%"><br /><br /><center><br /><form><br /><TD WIDTH=80%><br /><center><br /><TABLE ALIGN=MIDDLE BORDER=5 CELLPADDING=5><br /><TR BGCOLOR=#FFFFFF><br /><!--ROW 1--><br /><TD WIDTH=80%><br /><center><br /><TABLE ALIGN=MIDDLE BORDER=5 CELLPADDING=5><br /><TR BGCOLOR="#B6D4D2"><br /><!--ROW 1--><br /><td colspan=4><br /><center>Time Between Times Calculations - Multiple Days</center><br /><br /></td><br /></tr><br /><TR BGCOLOR="#B6D4D2"><br /><TD align="center" colspan=4><br />Required Data Entry<br /></td><br /></tr><br /><tr><br /><td align="center">Start / End</td><br /><td align="center">Hour</td><br /><td align="center">Minute</td><br /><td align="center">AM / PM</td><br /></tr><br /><br /><td align="center">Start time</td><br /><td align="center"><input type="text" name="hour1" size="5"></td><br /><td align="center"><input type="text" name="minute1" size="5"></td><br /><td align="center"><select name="period1"><br /><option value="1">AM<br /><option value="2">PM<br /></select><br /></td><br /></tr><br /><tr><br /><td colspan="3">    Add Complete Interim Days</td><td align="center"><input type="text" name="adays" size="5" value="0"></td><br /></tr><br /><tr><br /><td align="center">Start / End</td><br /><br /><td align="center">Hour</td><br /><td align="center">Minute</td><br /><td align="center">AM / PM</td><br /></tr><br /><td align="center">End time</td><br /><td align="center"><input type="text" name="hour2" size="5"></td><br /><td align="center"><input type="text" name="minute2" size="5"></td><br /><td align="center"><select name="period2"><br /><option value="1">AM<br /><option value="2">PM<br /></select><br /></td><br /></tr><br /><br /><tr><br /><td align="center" colspan=4 BGCOLOR="#B6D4D2"><br /><input type="button" value="Calculate" <br />onclick="h1=form.hour1.value;<br />h2=form.hour2.value;<br />m1=form.minute1.value;<br />m2=form.minute2.value;<br />days=form.adays.value;<br />am1=form.period1.options[period1.selectedIndex].value;<br />am2=form.period2.options[period2.selectedIndex].value;<br />if(h1 < 0 | h1 > 12) alert('Your start hour is not valid');<br />else if(h2 < 0 | h2 > 12) alert('Your end hour is not valid');<br />else if(m1 < 0 | m1 > 59) alert('Your start minute is not valid');<br />else if(m2 < 0 | m2 > 59) alert('Your end minute is not valid');<br />else form.answer.value=findtime(h1,h2,days,m1,m2,am1,am2);"><br />   <br /><input type="reset" value="Clear Values"><br /><br /></td><br /></tr><br /><TR BGCOLOR="#B6D4D2"><br /><TD align="center" colspan=4><br />Calculated Results<br /></td><br /></tr><br /><br /><tr><br /><td align="center" colspan="4"><br />Time Difference <input type="text" name="answer" size="40"><br /></td><br /></tr><br /></table><br /></form><br /></td><br /></tr><br /></table><br /><br /></center><br /></td><br /></tr><br /></table><br /></center><br /><br /></TD><br /></TR><br /></TABLE><br /></BODY> <br /></HTML><br /></pre>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2009 Jan 06, 2009

Copy link to clipboard

Copied

hi friend i have coding for this if ur interest me vino7tech@gmail.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines