Click to See Complete Forum and Search --> : time diff.


zuzupus
06-27-2003, 04:20 AM
Hi,

i am using PHP to get time while calculating time difference between finaland entry time using javascript as i dont no how to use with PHP if anybody knows it will really helpful for me
when final > entry time the difference showing is almost perfect while final<entry time then its showing -ve or some bigger tme diff. for eg. if fianl time is 02:55 and entry time is 10:41 the diff.shows 16:14 how to over come this...
if entry<=final then diff. is fine else its showing wrong diff. and the negative must be avoided
please help me with the script

[PHP code]
<td nowrap>
<select name="entry" size="1">
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
</select>
</td>
<td nowrap>
<select name="final" size="1" onChange="calculateIst()">
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
</select>
</td>
<td><input size="2" type="text" value="0" name="diff" readonly></td>
[/PHP code]

[JS code]
//calculate diff. when final tiem changed
<SCRIPT language="JavaScript">
function calculateIst()
{
var timeEntry = new Date();
var timeFinal = new Date();
var timeDiff = new Date();
var time =document.forms["tstest"].elements["entry"].value.split(":");
timeEntry.setHours(time[0]);
timeEntry.setMinutes(time[1]);
var time =document.forms["tstest"].elements["final"].value.split(":");
timeFinal.setHours(time[0]);
timeFinal.setMinutes(time[1]);
timeFinal.setTime(timeFinal.getTime() - timeEntry.getTime());
document.forms["tstest"].elements["diff"].value =timeDiff.getHours()-1 + ":" + timeDiff.getMinutes();
}
</script>
[/JS code]

pyro
06-27-2003, 07:11 AM
You should be able to use this to do that: http://forums.webdeveloper.com/showthread.php?s=&threadid=11253

zuzupus
06-27-2003, 08:02 AM
still its not working could u please modified this script and send me the actual time format i will be very thankful to you

thanks

zuzupus
06-27-2003, 08:22 AM
i tried below script amde change but when calculatifn time diff its showing error

function calculateIst()
{
var timeVon = new Date();
var vonhours = timeVon.getHours()
var vonminutes= timeVon.getMinutes()
if (vonhours<=9)
vonhours="0"+ vonhours
if (vonminutes<=9)
vonminutes="0"+vonminutes
var time=document.forms["tstest"].elements["von"].value
var timeBis = new Date();
var bishours = timeBis.getHours()
var bisminutes=timeBis.getMinutes()
if (bishours<=9)
bishours="0"+ bishours
if (bisminutes<=9)
bisminutes="0"+bisminutes
var time1=document.forms["tstest"].elements["bis"].value
*******upto time 1 its workign fine problem is this tiem diff.
its returning NaN**********
var timeIst = new Date();
timeIst.setTime(time.getTime()-time1.getTime())
document.forms["tstest"].elements["ist"].value =timeIst
}

please let me know where is the problem

thanks

zuzupus
06-27-2003, 09:17 AM
anybody in the house to solve this problem :)