Results 1 to 8 of 8

Thread: how to figure the difference in time

  1. #1
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Question how to figure the difference in time

    I have a calendar for scheduling and I would like to be able to tell the amount of time between the start-end.

    My table has [start] & [end] in 24 hr format.. so the input looks like this:

    start: 2200 end: 0400 //the problem that i cannot figure out how to get around is the computer doesnt know that 2400 is the end of the day.. can any help with ideas on this? Thanks..
    Last edited by crobinson42; 09-26-2010 at 02:59 AM.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    So you'd want it to know 2 hours for day 1, and 4 hours for day 2?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    Yes but i'd like to show the amount of hours for each shift over 30+ employees..

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I'm not clear what you are looking for, can you be more specific?
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I think:

    http://php.net/manual/en/datetime.diff.php

    may be what you need.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    i have a schedule with a database, i have 'start_time' & 'end_time'
    i'm using 24hr format so example would be:

    start= 1200 (12pm)
    end= 1600 (4pm)

    Is there a way to figure the diference in HOURS between the 2? Some start times will be 2100 (9pm) & end time 0200 (2am)

  7. #7
    Join Date
    Dec 2010
    Location
    Hyderabad, India
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    You should have your time in DATETIME data type. Subtracting the time will give you proper difference.

    Example query:

    PHP Code:
    $query " SELECT minute(TIMEDIFF(NOW(), timefield)) AS mindiff, hour(TIMEDIFF(NOW(), timefield)) AS hourdiff, day(TIMEDIFF(NOW(), timefield)) FROM tablename ORDER BY timefield "

  8. #8
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    why not use:

    PHP Code:
    $start=emplyee['start'];if ($start=='2400'$start='0';
    $end=employee['end'];if ($end=='2400'$end='0';

    $hours_worked=$end-$start;
    echo 
    "$hours_worked"
    Otherwise, could you give some examples of the output you want, especially with 0 hour.

    hour in the MySQL format is in 0 - 23 format ref.
    To choose the lesser of two evils is still to choose evil. My personal site

Bookmarks

Posting Permissions

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