php - 24 hours schedule- Time Diff
I have to build a 24 hours schedule for all personnel distributed around the globe.
So, for example, somebody can start working at 10:00 and end working at 19:00, so it is very simple to get the time difference since the end time and start time are on the same day. But, if I have somebody who starts working at 19:00 and ends at 04:00 on next day, I will get a negative time difference.
I need to do this continuously, not date specific but it has to repeat weekly. Can you please give me an idea what is the best way to do this?
+
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Solution:
I think a
case
statement does what you need:Answer
Solution:
You can use a simple if-statement:
Answer
Solution:
You can use PHP's time function for this task.
time()
returns the number of seconds since 1/1/1970.Store start time as (example)
and their end time to some time after that. If you subtract their start time from their end time the result will always be a positive number of seconds that they spent working. You also won't need the day column since the $time function returns the number of seconds since 1/1/1970, so you have the date there as well, for free.
In your UI, you can then format the resulting number of seconds to a usable time and date using PHP's date function.
Answer
Solution:
Thanks for your feedback guys. With your help, I did it as follows:
select IF( end_time > start_time, TIMEDIFF (end_time,start_time), TIMEDIFF (addtime(end_time,'24:00:00') ,start_time)) as Total_Hours from timetable;