Browse Groups

• ## Re: [phpXperts] Problem to calculate time difference from start time to end time

(3)
• NextPrevious
• Echo \$endtime and \$starttime first. See the result , if it is as per your requirement then go ahead. Otherwise fix them first.
Message 1 of 3 , Mar 21, 2012
View Source
Echo \$endtime  and  \$starttime first. See the result , if it is as per your requirement then go ahead. Otherwise fix them first.

On Wed, Mar 21, 2012 at 1:00 PM, Saiful Islam wrote:

Dear eXperts,

I have a problem to calculate time difference from start time to end time
/*****************************************************************/
\$starttime = explode(":",\$resultExamCompletedUser['StartTime']);     // say \$resultExamCompletedUser['StartTime'] =  11:08:21
\$starttime = mktime(\$starttime[0],\$starttime[1],\$starttime[2]) ;

\$endtime = explode(":",\$resultExamCompletedUser['ActualEndTime']);  // say \$resultExamCompletedUser['ActualEndTime'] = 11:08:38
\$endtime = mktime(\$endtime[0],\$endtime[1],\$endtime[2]) ;

\$requiredtime = \$endtime - \$starttime;
\$time_diff = date('h:i:s', \$requiredtime);

/*****************************************************************/

But when i echo \$time_diff, it shows Required Time: 12:00:17, but actually time required time is 00:00:17

Can any one help me to solve the problem?

Regards,
Saiful Islam
http://saifulbd.com/

• Using PHP5 DateTime and DateInternval class and some tricks. \$dt1 = new DateTime( today . 11:08:21 ); \$dt2 = new DateTime( today . 11:08:38 ); echo
Message 1 of 3 , Mar 22, 2012
View Source
Using PHP5 DateTime and DateInternval class and some tricks.

\$dt1 = new DateTime("today ". "11:08:21");
\$dt2 = new DateTime("today ". "11:08:38");
echo \$dt1->diff(\$dt2)->format("%H hours %I minutes %s seconds");

Output
=====

00 hours 00 minutes 17 seconds

--
ImgSign.com | A dynamic signature machine

Innovation distinguishes between follower and leader

Your message has been successfully submitted and would be delivered to recipients shortly.
• Changes have not been saved
Press OK to abandon changes or Cancel to continue editing
• Your browser is not supported
Kindly note that Groups does not support 7.0 or earlier versions of Internet Explorer. We recommend upgrading to the latest Internet Explorer, Google Chrome, or Firefox. If you are using IE 9 or later, make sure you turn off Compatibility View.