Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Get the time differance??

    hi i have problem that getting time differance

    if $b2=18:02:15

    $b3=18:05:15

    Im not getting the correct time different as 3 min

    $b2=date("H:i:s", $barcodetime);

    $b3=date("H:i:s", $Barcode_Time1);

    $diff=strtotime($b3)-strtotime($b2);

    $diff1=date("H:i:s", $diff);

    plz solve this problem

  • #2
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Well, since your time only has a specific clock time no day or months, you can explode the time and convert it into seconds. Like this:

    PHP Code:
    $tme explode(":"$b2);

    $secs = ($tme[0] * 3600) + $tme[1] * 60 $tme[2]; 
    Do the same for the second time then subtract them. What you will have is the time difference in seconds. You can do an if > 60 to convert into minutes, if > 3600 to convert to hours.

    And also try to format your PHP code.

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,918
    Thanks
    15
    Thanked 227 Times in 227 Posts
    If you just want the difference, use UNIX Time, which is just time(); in php. It outputs the time in seconds from the date when the UNIX 'clock' was started. You just have to take the difference between the two numbers. One day is 86400 seconds.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #4
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    DrDos, if you check the times he has provided...they do not have the day, month or year. So using time() will not really give him a time since the UNIX clock was started.

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,918
    Thanks
    15
    Thanked 227 Times in 227 Posts
    Quote Originally Posted by Redcoder View Post
    DrDos, if you check the times he has provided...they do not have the day, month or year. So using time() will not really give him a time since the UNIX clock was started.
    Quite correct, but nothing really prevents him from adding it into the code somewhere, and it's a lot easier to deal with and compare.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •