Solved

Start and End Time over corss over midnight

Posted on 2011-02-28
9
275 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:mishlce
  • 5
  • 4
9 Comments
 
LVL 40

Expert Comment

by:Sharath
ID: 35002011
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.
0
 

Author Comment

by:mishlce
ID: 35002088
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.  

0
 
LVL 40

Expert Comment

by:Sharath
ID: 35002729
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");

Open in new window


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");

Open in new window


Now query these two queries.
SELECT t1.MinStartTime, 
       t2.MaxEndTime 
  FROM (MinStartTime AS t1 
        INNER JOIN MaxEndTime AS t2 
          ON DATEADD("d",1,t1.StartTime) = DATEVALUE(t2.EndTime));

Open in new window

0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 35002757
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");

Open in new window


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");

Open in new window


Now query these two queries.
SELECT t1.MinStartTime, 
       t2.MaxEndTime 
  FROM (MinStartTime AS t1 
        INNER JOIN MaxEndTime AS t2 
          ON DATEADD("d",1,t1.StartTime) = DATEVALUE(t2.EndTime));

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:mishlce
ID: 35032013
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
0
 
LVL 40

Expert Comment

by:Sharath
ID: 35032215
You did not mention all the possible scenarios in the first post. Anyway, could you post the expecetd result for the latest post?
0
 

Author Comment

by:mishlce
ID: 35037801
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.
0
 
LVL 40

Expert Comment

by:Sharath
ID: 35039594
Could you post the link for that question?
0
 

Author Comment

by:mishlce
ID: 35039826
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need Distinct Value from Joined Tables in MSSQL 5 51
how to open abcd.txt.orig file? 10 44
Microsoft 365 versus MicroSoft 2013/2016 8 64
Excel 2016 - Black cell borders 11 27
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now