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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    124
    Thanks
    6
    Thanked 0 Times in 0 Posts

    php calculate time differance problem

    hi i have this code

    $sqlstr13="SELECT * FROM barcode WHERE Internal ='$preinternal' ";

    $result13= mysql_query($sqlstr13);
    $recordinput13= mysql_fetch_array($result13);

    $timeeend=$recordinput13['timeB'];

    $today2 = date("G:i:s");

    so now i`m subtracting

    $diff=strtotime($today2)-strtotime($timeeend);

    in hear working perfectly for the time differance less than 1 minte

    but time differance above 1 min it will give zero

    plz help me to solve this problemmmmmmmm

    with the code

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    This line:
    $today2 = date("G:i:s");

    Should be:
    $today2=time();

    This line:
    $diff=strtotime($today2)-strtotime($timeeend);

    Change to:
    $diff=$today2-strtotime($timeeend);

    time() is the UNIX timestamp right now, for your timezone.
    Remember that you're using the server timezone unless you specify it otherwise.

    The next issue will be the format of $recordinput13['timeB']
    Can you show us how one of those values are formated in the column?

    The difference between two UNIX timestamps is in seconds (that's the resolution);
    So, you might get a difference of 97. That's 97 seconds. Or a negative difference is possible.


    .
    Last edited by mlseim; 01-18-2012 at 03:41 PM.


  •  

    Posting Permissions

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