/    Sign up×
Community /Pin to ProfileBookmark

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]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@pyroJun 27.2003 — You should be able to use this to do that: http://forums.webdeveloper.com/showthread.php?s=&threadid=11253
Copy linkTweet thisAlerts:
@zuzupusauthorJun 27.2003 — 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
Copy linkTweet thisAlerts:
@zuzupusauthorJun 27.2003 — 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
Copy linkTweet thisAlerts:
@zuzupusauthorJun 27.2003 — anybody in the house to solve this problem ?
×

Success!

Help @zuzupus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...