I have a table that has two fiels, Time_in and Time_out. I need to figure out some information about the entries in those fields. They would look like this:
Time_in Time_out
7/13/2005 8:00:00 AM 7/13/2005 5:00:00 PM 7/14/2005 8:00:00 AM 7/14/2005 5:00:00 PM 7/15/2005 8:00:00 AM 7/15/2005 5:00:00 PM 7/16/2005 8:00:00 AM 7/16/2005 5:00:00 PM 7/17/2005 8:00:00 AM 7/17/2005 5:00:00 PM 7/20/2005 8:00:00 AM 7/20/2005 5:00:00 PM 7/21/2005 8:00:00 AM 7/21/2005 5:00:00 PM 7/22/2005 8:00:00 AM 7/22/2005 5:00:00 PM 7/23/2005 8:00:00 AM 7/23/2005 5:00:00 PM
Lets take the first entry. I need to know how many of the total minutes between Time_in and Time_out were worked between the hours of 7:01 am and 5:00 pm, 5:01 pm and 11:00 pm and 11:01 pm and 7:00 am.
I used this to get the minutes elapsed between the two:
SELECT Time_in, Time_out, DATEDIFF([minute], Time_in, Time_out) AS MINUTES, DATEDIFF([Minute], Time_in, '5:00:00 PM 7 / 13 / 2005 ') AS FIRSTSHIFT
FROM Timeattendance_T
This does return the total minutes worked and the total elapsed between Time_in and 5:00 pm, but if the day is not 7/13/2005 it messes it up and it does not give me the minutes from 7-5, only Time_in to 5:00. I guess I need to replace the 7/13/2005 with a date part of Time_out? Anyway, I am rambling. I would like the output something like this:
Time_in Time_out 1st Shift 2nd Shift 3rd Shift
08:00 AM 8:00 PM 9 3 0
06:00 AM 3:00 PM 8 0 1
I am at a loss as to how to do this. ANY HELP would be greatly appreciated.
Thanks,
Shannan
Time_in Time_out
7/13/2005 8:00:00 AM 7/13/2005 5:00:00 PM 7/14/2005 8:00:00 AM 7/14/2005 5:00:00 PM 7/15/2005 8:00:00 AM 7/15/2005 5:00:00 PM 7/16/2005 8:00:00 AM 7/16/2005 5:00:00 PM 7/17/2005 8:00:00 AM 7/17/2005 5:00:00 PM 7/20/2005 8:00:00 AM 7/20/2005 5:00:00 PM 7/21/2005 8:00:00 AM 7/21/2005 5:00:00 PM 7/22/2005 8:00:00 AM 7/22/2005 5:00:00 PM 7/23/2005 8:00:00 AM 7/23/2005 5:00:00 PM
Lets take the first entry. I need to know how many of the total minutes between Time_in and Time_out were worked between the hours of 7:01 am and 5:00 pm, 5:01 pm and 11:00 pm and 11:01 pm and 7:00 am.
I used this to get the minutes elapsed between the two:
SELECT Time_in, Time_out, DATEDIFF([minute], Time_in, Time_out) AS MINUTES, DATEDIFF([Minute], Time_in, '5:00:00 PM 7 / 13 / 2005 ') AS FIRSTSHIFT
FROM Timeattendance_T
This does return the total minutes worked and the total elapsed between Time_in and 5:00 pm, but if the day is not 7/13/2005 it messes it up and it does not give me the minutes from 7-5, only Time_in to 5:00. I guess I need to replace the 7/13/2005 with a date part of Time_out? Anyway, I am rambling. I would like the output something like this:
Time_in Time_out 1st Shift 2nd Shift 3rd Shift
08:00 AM 8:00 PM 9 3 0
06:00 AM 3:00 PM 8 0 1
I am at a loss as to how to do this. ANY HELP would be greatly appreciated.
Thanks,
Shannan