Log in

View Full Version : how to figure the difference in time



crobinson42
09-26-2010, 02:51 AM
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..

bluewalrus
09-26-2010, 03:27 AM
So you'd want it to know 2 hours for day 1, and 4 hours for day 2?

crobinson42
09-26-2010, 03:29 AM
Yes but i'd like to show the amount of hours for each shift over 30+ employees..

bluewalrus
09-27-2010, 04:10 AM
I'm not clear what you are looking for, can you be more specific?

jscheuer1
09-27-2010, 04:26 AM
I think:

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

may be what you need.

crobinson42
12-31-2010, 01:08 AM
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)

VijayKanta
12-31-2010, 06:27 AM
You should have your time in DATETIME data type. Subtracting the time will give you proper difference.

Example query:



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

james438
12-31-2010, 06:23 PM
why not use:


$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 (http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_hour).