473,508 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help Getting the day shift after midnight



Hello there,
I am having a small problem which been challenging me for few days and
need help or advice.

I am trying to calculate the day-shift for employees based on the time
they started and finish working, I will only have 2 shifts 1 or 2 .
Shift one changes based on the location however any thing else is shift
2. The problem I am having is when someone signed in after midnight; I
need to report his time under shift 2 for the previous day date. So if
he signs at 12:30 AM on 12-12-2006, I need to report that as shift 2 on
12-11-2006 and that’s where my problem is. Is there a way to subtract
the date by 1. I am using SQL Server and here is a simplified tables I
am working with:
Employee table
EmployeID LocationID StartTime EndTime
123 555 11:00:00 AM 3:00:00 PM
183 559 7:00:00 AM 11:00:00 AM


Shift table
ShiftNumber LocationID StartTime EndTime
1 555 7:00:00AM 2:00:00PM
2 555 2:00:00PM 12:00:00AM
1 559 6:00:00AM 4:00:00PM
…..
So I am trying something like

CASE WHEN (select ShiftNumber FROM Shift WHERE LocationID=TR.LocationID
AND
(TR.StartTime>=StartTime
AND
TR.EndTime<= EndTime)
) =1 THEN 1
ELSE
WHEN (select ShiftNumber FROM Shift WHERE LocationID=TR.LocationID
AND
(TR.StartTime>=StartTime
AND
TR.EndTime<= EndTime)
) =2 THEN 2
ELSE
?????????????? NEED HELP HERE WHEN EMPLOYEE SIGN AFTER MIDNIGHT
END
)
FROM

Employee TR

INNER JOIN Shift ON LocationID = TR.LocationID


*** Sent via Developersdex http://www.developersdex.com ***
Dec 2 '06 #1
3 4177
>2. The problem I am having is when someone signed in after midnight; I
>need to report his time under shift 2 for the previous day date.
It is technically correct to say that all times are after midnight, it
is just a matter of by how much. So the question is, just what is the
window for which StartTime always means shift 2 for the previous day?
Obviously it starts at 00:00:00 hours, but when does it end? 05:59:59?
Some other time? Without such a time I can not see any way to do
this.

My tendency would be to write the first WHEN clause of the CASE to
trap the after-midnight second-shift of yesterday cases based on
StartTime falling within that window. Then deal with the other cases
in the second and following WHEN clauses. Of course the CASE will
have to be written using correct syntax, but that is another issue
altogether.

Roy Harvey
Beacon Falls, CT

On 02 Dec 2006 01:10:05 GMT, Amy Smith <am******@hotmail.comwrote:
>

Hello there,
I am having a small problem which been challenging me for few days and
need help or advice.

I am trying to calculate the day-shift for employees based on the time
they started and finish working, I will only have 2 shifts 1 or 2 .
Shift one changes based on the location however any thing else is shift
2. The problem I am having is when someone signed in after midnight; I
need to report his time under shift 2 for the previous day date. So if
he signs at 12:30 AM on 12-12-2006, I need to report that as shift 2 on
12-11-2006 and that’s where my problem is. Is there a way to subtract
the date by 1. I am using SQL Server and here is a simplified tables I
am working with:
Employee table
EmployeID LocationID StartTime EndTime
123 555 11:00:00 AM 3:00:00 PM
183 559 7:00:00 AM 11:00:00 AM


Shift table
ShiftNumber LocationID StartTime EndTime
1 555 7:00:00AM 2:00:00PM
2 555 2:00:00PM 12:00:00AM
1 559 6:00:00AM 4:00:00PM
…..
So I am trying something like

CASE WHEN (select ShiftNumber FROM Shift WHERE LocationID=TR.LocationID
AND
(TR.StartTime>=StartTime
AND
TR.EndTime<= EndTime)
) =1 THEN 1
ELSE
WHEN (select ShiftNumber FROM Shift WHERE LocationID=TR.LocationID
AND
(TR.StartTime>=StartTime
AND
TR.EndTime<= EndTime)
) =2 THEN 2
ELSE
?????????????? NEED HELP HERE WHEN EMPLOYEE SIGN AFTER MIDNIGHT
END
)
FROM

Employee TR

INNER JOIN Shift ON LocationID = TR.LocationID


*** Sent via Developersdex http://www.developersdex.com ***
Dec 2 '06 #2


Roy,
the end time after mindnight will be always 6:00:00AM so from 00:00:00
AM to 6:00:00 AM , it should go to the pervious day's shift 2 . Again my
issue is when finding the that the start time fall withing that time how
do I pretend the date as the previous date? Do I subtract the date ? Is
there a function to do that ? thanks Roy

*** Sent via Developersdex http://www.developersdex.com ***
Dec 2 '06 #3
Amy Smith (am******@hotmail.com) writes:
the end time after mindnight will be always 6:00:00AM so from 00:00:00
AM to 6:00:00 AM , it should go to the pervious day's shift 2 . Again my
issue is when finding the that the start time fall withing that time how
do I pretend the date as the previous date? Do I subtract the date ? Is
there a function to do that ? thanks Roy
convert(char(8), dateadd(HOUR, -6, EndTime), 112)

The dateadd() functions brings the EndTime six hours back in time. The
convert to char(8) with code 112 strips of the time portion.

You can read more about dateadd and other datetime functions in Books
Online. You can also read about convert() under the topic CAST and CONVERT.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7767
by: itzik peretz | last post by:
i have an array of bytes from variable length and i need to shift it in variable size of bits between 1-7. do someone know about constructive way to do it? beside iterate the array and deal with...
7
1425
by: angelasg | last post by:
Here is sample data I'm working with: ID ShiftDate SegTime 99 5/2/2005 5/2/2005 1:00:00 PM 99 5/2/2005 5/2/2005 1:04:00 PM 99 5/2/2005 5/2/2005 1:43:00 PM 99 5/2/2005...
11
4020
by: Kenneth Lantrip | last post by:
Anyone got any ideas as to how this process could be improved for speed? this is what I have... Dim j, q As Integer Dim x(16), y(16) As Byte x.CopyTo(y, 0) ' shift left circular 24 bits
2
2920
by: mtech1 | last post by:
Access 2003 I need to create a query to view data by 3 - 24 hour shifts. Ex: There are 3 shifts, each shift is 24 hours starting at 0700 through 0700. Each shift is designated as A, B, or C. ...
7
7191
by: yancheng.cheok | last post by:
hello all, in my memory content says, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 ... 0xff i wish to shift it n bits. please note that, not n bye, but n bit, and n can be any value 0, 1,...
5
3519
by: Screaming Eagles 101 | last post by:
Hi, I'm looking for some code to find the right work shift according to a specific date and time. This one worked fine in VB6, but somewhere I do not succeed in converting it to VB2005 code.......
7
1173
by: Bint | last post by:
Hi, What is a simple way to shift the elements in an array, circularly? Is there a way to do it so that you don't need a separate storage array? IE I want to shift array A{1,2,3,4,5,6,7,8} by...
0
1157
by: rag84dec | last post by:
Hi, I need to shift 32 bits in perl. Like $t=0xe1; $r=$t<<32; but it is not working since scalar can hold 32 bits ...can u tell me how to make it work??? i want to send this to...
3
3052
by: koti688 | last post by:
how to get the column names and the values of them in select statment. I have a packaze like this named ADB.pm package ADB; use DBI; @ISA = ('Exporter');
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.