Loading ...
Sorry, an error occurred while loading the content.

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

Expand Messages
  • foysal foysal
    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
    • 0 Attachment
      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 <abssaiful@...> 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
      Gazipur, Bangladesh
      http://saifulbd.com/


    • shiplu
      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 2 of 3 , Mar 22, 2012
      View Source
      • 0 Attachment
        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

        Links of interest


        --
        Shiplu.Mokadd.im
        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.