# Start and End Time over corss over midnight

I want the Max PM Start Time each day and the Max AM End Time the following day
This will then reach the shift worked starting with first acct worked start time and last account
worked end time. I want this for each day.  I am looking for qry to do this in access as my data is stored in an access table.

There are multiple start and end times of svc I just want to see first of shift and end of shift.

So it looks like this.

Start Time:                       End Time:                    Hours Worked
11/8/10 10:10 PM             11/9/10 2:39 AM             4.23
11/9/10 7:52 PM               11/10/10 12:14 AM         4.22

Book1.xls
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Data EngineerCommented:
Do you want the MAX PM StartTime or MIN PM StartTime? In your excel sheet, the MAX PM StartTime is 11/8/10 11:45 PM not 11/8/10 10:10 PM.
Author Commented:
Sorry I want the 11/8/10 10:10 PM. which would be the Min PM start time.  and then the Max AM End time following day the 9th.  I am trying to  determine the hours of worked for each person that works the PM overnight shift.

Data EngineerCommented:
Create two queries as below and name them as MinStartTime and MaxEndTime respectively.

MinStartTime:
``````SELECT FORMAT(Sheet2.[End Time],"Medium Date") AS EndTime,
MAX([End Time])                         AS MaxEndTime
FROM Sheet2
WHERE HOUR([End Time]) < 12
GROUP BY FORMAT(Sheet2.[End Time],"Medium Date");
``````

MaxEndTime:
``````SELECT FORMAT(Sheet2.[Start Time],"Medium Date") AS StartTime,
MIN([Start Time])                         AS MinStartTime
FROM Sheet2
WHERE HOUR([Start Time]) >= 12
GROUP BY FORMAT(Sheet2.[Start Time],"Medium Date");
``````

Now query these two queries.
``````SELECT t1.MinStartTime,
t2.MaxEndTime
FROM (MinStartTime AS t1
INNER JOIN MaxEndTime AS t2
``````
Data EngineerCommented:
I have misplaced the query names.

MaxEndTime:
``````SELECT FORMAT(Sheet2.[End Time],"Medium Date") AS EndTime,
MAX([End Time])                         AS MaxEndTime
FROM Sheet2
WHERE HOUR([End Time]) < 12
GROUP BY FORMAT(Sheet2.[End Time],"Medium Date");
``````

MinStartTime:
``````SELECT FORMAT(Sheet2.[Start Time],"Medium Date") AS StartTime,
MIN([Start Time])                         AS MinStartTime
FROM Sheet2
WHERE HOUR([Start Time]) >= 12
GROUP BY FORMAT(Sheet2.[Start Time],"Medium Date");
``````

Now query these two queries.
``````SELECT t1.MinStartTime,
t2.MaxEndTime
FROM (MinStartTime AS t1
INNER JOIN MaxEndTime AS t2
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
This worked perfectly for the over midnight/switching of days (Cross Over).  But it did not work for other types of shifts.  I have attached all scenarios I would run accross to see if you can help.  The attached file is exactly as the data is represented in the access table.  SEE ATTACH.
Anna.xls
Data EngineerCommented:
You did not mention all the possible scenarios in the first post. Anyway, could you post the expecetd result for the latest post?
Author Commented:
I have re submitted the question pls see 03/04/11 07:00 AM, ID: 26864074 :  Employee Shift Calculation.  The spreadsheet is attached with this quesiton to show data and results wanted.
Data EngineerCommented:
Could you post the link for that question?
Author Commented:
This will be done in Access not SQL.  I updated the comment as I chose wrong zone originally. Here is the link.

http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_26864074.html
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.