Hi friends
i have a starttime in the format of $starttime = time() and endtime as $endtime = time()
now i am trying to come out with the time difference $endtime-$starttime in the minutes
how can i get the minutes from this output ????
how to get minutes from time difference coming in time()
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: how to get minutes from time difference coming in time()
I am doing this , tell me whether it is right or wrong?
$starttime = time(); this is when my quiz is start
$endtime = time(); this is when my quiz is end
$total_time_taken = $endtime-$starttime;
$real = date("i",$total_time_taken);
$starttime = time(); this is when my quiz is start
$endtime = time(); this is when my quiz is end
$total_time_taken = $endtime-$starttime;
$real = date("i",$total_time_taken);
Re: how to get minutes from time difference coming in time()
You have to convert the times to unix timestamp before performing the '-' operation.
Try this code below -
Try this code below -
Code: Select all
<?php
$nowdate = strtotime("8 April 2007");
$thendate = strtotime("2 May 2006");
$datediff = ($nowdate - $thendate);
echo $datediff." Seconds<br>";
echo round($datediff / 60)." Minutes<br>";
echo round($datediff / 3600)." Hours<br>";
echo round($datediff / 86400)." Days<br>";
?>
Re: how to get minutes from time difference coming in time()
>You have to convert the times to unix timestamp before performing the '-' operation.
but i think the function time() also gives current time in the unix time stamp
is it true ?
http://in2.php.net/time
but i think the function time() also gives current time in the unix time stamp
is it true ?
http://in2.php.net/time
Re: how to get minutes from time difference coming in time()
Yes it's true. What I mean is - to find the difference using strtotime() function, you have to pass an english date as an argument in strtotime().djdon11 wrote:>You have to convert the times to unix timestamp before performing the '-' operation.
but i think the function time() also gives current time in the unix time stamp
is it true ?
http://in2.php.net/time
- JamesRavenscroft
- Forum Newbie
- Posts: 10
- Joined: Thu Jan 31, 2008 3:45 am
- Location: West Midlands, United Kingdom
Re: how to get minutes from time difference coming in time()
I was pretty sure that was the case. The approach you are taking is exactly how I would do it.
Maybe do some debugging. Print the start time, end time and the difference time and see if you get output for all 3. Maybe one of the variables is being set funny. Although, I can't see why that would be the case.
Another alternative might be to try manually setting the number to minutes like so:
Maybe do some debugging. Print the start time, end time and the difference time and see if you get output for all 3. Maybe one of the variables is being set funny. Although, I can't see why that would be the case.
Another alternative might be to try manually setting the number to minutes like so:
Code: Select all
$starttime = time(); this is when my quiz is start
$endtime = time(); this is when my quiz is end
$total_time_taken = $endtime-$starttime;
$minutes = $total_time_taken / 60; //divide by 60 to get minutes from seconds.