How to Compare day and night based on current time

Hi,
Day starts 08:00 -18:00(start time-end time)
Night starts 18:00-08:00(st-et)
for day it's easy I compare current time between st and et in logs table.
for night if I use the same the process it falls after midnight coz current time is not in between st and et. 
Example : 00:00 between 18:00 and 08:00.
To over come above I stared comparing with datetime.
for day it's fine.
for night , it inserts one log at 18:00 and updates till 23:59, after 00:00 it's not updating and adds new record then problem starts.
can anyone give me some idea how to handle this please?
Cheers :)

create table #t (st time, et time)
insert into #t values ('08:00','18:00')
insert into #t values ('18:00','08:00')
declare @time time='00:00';
select st, et from #t
where case when @time='00:00' then '23:59'
else @time end >st and et< st
or @time between st and et
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • How to filter IN and OUT punch timings for Attendance in Day and Night shifts in oracle SP?

    I am developing Attendance system which having day and night shift I am unable to filter the IN and OUT punches of the employees? below is my current logic
    shift timings on 29-Jun-2013 IN 22:00 OUT 07:00 and on 30-Jun-2013 IN 15:00 OUT 22:30
    I am filtering the IN and OUT punches based on shift timings and swipe time along with date, but when the employee changing from night shift to day shift I am getting problem.
    the below is the one scenario
    the employee : 101 has worked on 29-Jun-2013 on night shift punched at 22:00 and he left at next day means 30-Jun-2013 07:00 AM and again the same day (30-Jun-2013) he came to office at 15:00 on 30-Jun-2013 and he left at 22:30 on the same day now if the punches will come daily then there is no problem, however due to any problem punches are not received for 30-Jun-2013 07:00 AM then the punches IN 15:00 OUT 22:30 on 30-jun-2013 already in database now the out punch of 29-Jun-2013 is 30-Jun-2013 at 07:00 AM it is difficult to find this as previous day out punch
    Note: some times the employees forgot to swipe IN/OUT punch
    so if any body have solution please update

    Like
    Employee ID
    Date
    Time
    PunchType
    Comments
    101
    29-Jun-13
    22:00
    IN
    101
    30-Jun-13
    7:00
    OUT
    If this row is not there & next row is with IN flag, the email should be triggered to employee
    101
    30-Jun-13
    15:00
    IN
    101
    30-Jun-13
    22:00
    OUT
    I have another scenario for you -
    Employee ID
    Date
    Time
    PunchType
    Comments
    101
    29-Jun-13
    22:00
    IN
    101
    30-Jun-13
    7:00
    OUT
    101
    30-Jun-13
    11:30
    IN
    how do you know it is not the continuation of 29-Jun shift? I believe you might have to define a rule here that if a person swipes IN say in n(4.5 in this case) hrs gap, it would be considered as Next Day
    101
    30-Jun-13
    22:00
    OUT
    Regards,

  • Comparing HP to Toshiba is like day and night!

    Hi! I guess this is kind a like posting in the back woods. Not many visitors come here. I will post my message here, as it would probably get moved here any way.
    I was a register member on the Toshiba forum for a considerable time. I have a Toshiba laptop, but only until it starts having hardware problems and then I will purchase a HP. I have only been a member here for a short time, but I can see the difference between HP and Toshiba is like day and night. Not only is HP a better product, the support is 100 times better than the support for Toshiba. There are more smarter and qualified people helping on this forum by far. There are maybe 3 members on the Toshiba forum that have any computer skills and the moderators seem to want it that way. I can see that the hp products are improving every day and so is the HP support here on the forum.
    You're doing very well in my books HP. Keep up the good work. I recommend you to all the senior citizens in my Village. I felt like I had to post this message on the HP forum even though i doubt if many will see it.
    Thanks HP!
    Dokie!
    I wish Google would pick this up and post it on the internet. That would make old Dokie's day.

    Dokie thanks for the nice post and thanks for the words of encouragement.
    - I worked for HP.

  • My phone keeps ringing at all hours day and night

    My house phone keeps ringing at all hours day and night.  It only rings once or twice.  If I pick it up the line is dead.  I think it might be from skype because I noticed a strange California area code phone number once and a friend said that was a phony number that skype uses to send out calls.  Can I find out who keeps calling me?  This is telephone harassment!

    I think you can try contacting your telephone service provider first for possibly more specific/accurate information.  Then if it is indeed a Skype number/call, you can submit a report to Skype.
    IF YOU FOUND OUR POST USEFUL THEN PLEASE GIVE "KUDOS". IF IT HELPED TO FIX YOUR ISSUE PLEASE MARK IT AS A "SOLUTION" TO HELP OTHERS. THANKS!
    ALTERNATIVE SKYPE DOWNLOAD LINKS | HOW TO RECORD SKYPE VIDEO CALLS | HOW TO HANDLE SUSPICIOS CALLS AND MESSAGES
    SEE MORE TIPS, TRICKS, TUTORIALS AND UPDATES in
    | skypefordummies.blogspot.com | 

  • How to compare date and time together

    Hi,
    How to compare Date and Time together?
    For example in a database table there are two fields rundate and runtime.  I want to compare these two with perticular date and time in the program.  Like, I want to pull all the records where the records's date and time are less than a perticular date and time in the program.
    Hope the question is clear...
    Thanks.
    Kavita

    Hi Kavita
    There is no as such Date and Time Comparision FM in Standard SAP  But You can define your own like this
    <b>FUNCTION ZAV4_COMPAREDATETIME.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(DATE1) TYPE  DATS
    *"     REFERENCE(TIME1) TYPE  TIMS
    *"     REFERENCE(DATE2) TYPE  DATS
    *"     REFERENCE(TIME2) TYPE  TIMS
    *"  EXPORTING
    *"     VALUE(TWOISMORETOPICAL) TYPE  C
      twoismoretopical = ''.
      if date2 > date1.
        twoismoretopical = 'X'.
      else.
         if date2 = date1 and time2 > time1.
           twoismoretopical = 'X'.
         endif.
      endif.
    ENDFUNCTION.</b>
    Regards
    Mithlesh

  • How do i add and email based submit button to a form

    how do i add and email based submit button to a form

    See this: http://help.adobe.com/en_US/acrobat/using/WSBB6EF75F-BC3D-4094-B787-FB76DAE1EBDC.w.html

  • My iPhoto library just reverted to an old library: How can I find, and re-access my current library?

    My iPhoto library just reverted to an old library: how can I find and re-access my current library?  I opened my iPhoto, and got the message that it needed to "update" to use this library.  I thought maybe there had been a software update since I last opened the program (2 days ago).  The library it opened was saved in a file on the desk-top.  My current file was just in iPhoto.  Please help!

    Best option: Restore from your back up.
    Otherwise:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • How to stream Webcam and Desktop at the same time?

    Hey Guy,
    I just got a little Problem with  FMLE... I want to stream live during a Game, but I dont know how to stream Desktop and Webcam at the same time ^^. The streaming Platform i want to use is twitch.tv.. the most common Gamin Platform I think...
    I got an IMac i7.
    Pls help me   I dont get how all these ProGamer do it -.-
    Thanks in advance
    Kathi

    You're going to need additional software or hardware.  If you're running a Macintosh, try CamTwist.  It's free and allows you to create virtual "cameras" from just about anything you can see on your computer.  It's a bit clunky getting used to the interfact and how it works, however.
    Hardware solutions (like scanline converters and video switchers) can get pretty expensive.  So you may want to go with a piece of software that can handle on-the-fly video compositing/switching.  There are two applications that come to mind right off the bat -- and lucky for you, both of them can also output to a live streaming server. 
    Wirecast is a popular choice, although the pricing starts around $500.  It's Macintosh/Windows.
    A very popular choice among gamers is XSplit (Windows only) and is a subscription-based model (you pay a small fee by the month, quarter, or year).  XSplit has some very impressive compression happening under the hood, and was originally designed for gamers who wanted to share their desktop, XBOX, or PS3 adventures... all while also being able to lay over banners, PIP (picture-in-picture) of themselves, or anythhing else they wanted to clutter the screen with.
    If you're running on Windows, give XSplit at shot.  It can easily handle your desktop (or most anything else) as a "camera" as well as being able to lay your webcam on top of the desktop feed.

  • Start recording video at a set time of day and off at a set time of day, and or can start rec video when motion detected, till no motion detected for a set period

    is there an app for iphone which can be set to start recording video at a set time of day and off at a set time of day, and or can start rec video when motion detected, till no motion detected for a set period. basically someone is vandalising my vehicle and i really really want to catch the mongrel
    thanks for any suggestions

    Nope.

  • How to post aquisition and depriciation at the same time

    Hi Gurus,
    Could you please let me know how to post aquistion and depriciation at the same time.

    Hi
    What do you mean by postin at a time, is it uploading the balances to SAP
    if not there is no question of posting at a time
    Thanks
    Kameshwar Rao

  • HT3275 Have OS 10.7.5. Computer off three days and now message comes that Time Machine could not complete backup because the "/volumes/PH's timecapsulPro.sparsebundle" is already in use. Whats that about?

    Have OS 10.7.5. Computer off three days and now message comes that Time Machine could not complete backup because the "/volumes/PH's timecapsulPro.sparsebundle" is already in use. Whats that about?

    Two Solutions for "sparse bundle already in use" Error
    Simple solution (from Bob Timmons):
    1. Make sure that no other Macs are backing up the Time Capsule at the time
    2. Pull the power cord from the back of the Time Capsule
    3. Count to ten
    4. Plug the power cord back into the back of the Time Capsule
    If Simple doesn't work:
    The Backup disk image ... sparsebundle ... is already in use.

  • Mountain Lion update continues all day and night.  How do I finish it, or stop it?

    this "update" (2013 003 1.0) continues days and months now.  I can't get it to stop.  Can't use ITunes because of it.  Can't turn off the machine (Mac) because of it.  Got any suggestions?

    Never mind, I see it's Mountain Lion.
    Can you check in your Applications Folder to see if the installer is still there. You are confused on some things, because the installer should be giving you a DOWNLOAD text on the purchases page, not install.

  • How to compare char and numc in select query

    Hi  Experts,
    I am using For all entries  to combine two tables.
    I want to fetch the data from these tables.
    The field in one table char, and in another the field is numc.
    1st Query from table BDCP2  and get the tabkey value is like (2000000000000000000086200000000000000000000)
    2nd query     For all entries found,
    query table ESTMJ with the following parameter.
         ESTMJ-RECN = BDCP2-TABKEY+3(20)
    1.TABKEY         CHAR     254
    2.RECN         NUMC     20     
    How to compare these two ?
    Regards,
    Bindhu Priya.

    for  two fields numc & char , please check out their Conversion routine in their respective Database table.
    1st in SE11-> enter table names in different sessions. and check out the data domain used by this fields
    In their respective domains of fields, click on tab 'DEFINITIONS', then check out the conversion routines in Output Characteristics of the Data Domain of field
    From my point of view, both the Conversion routines should be the same.
    If Conversion Routines are not there, then insert suitable Conversion routine for both the fields domain
    For help for for conversion routines:
    conversion routine
    http://help.sap.com/saphelp_46c/helpdata/en/cf/21ee19446011d189700000e8322d00/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/35/26b217afab52b9e10000009b38f974/content.htm
    http://abaplovers.blogspot.com/2008/03/conversion-routines-in-sap.html
    hope this solution could solve your issue..
    <begging removed by moderator>
    Gaur Mayank
    Edited by: Gaur Mayank on Nov 5, 2011 10:40 AM
    Edited by: Thomas Zloch on Nov 6, 2011 3:59 PM

  • Day and Night background

    I have made my website:
    http://cpower.co.il
    and I have to SWF's one for the day and one for the night. I
    used a JS script to detect the user's
    time and by that to activate the currect SWF but I find it
    hard when I want to update the FLA of the day.FLA I have also to
    update the night.FLA. Therefore, is there a way I can make that
    detection of user's time using ActionSctipt in the FLA of so I will
    have one FLA and in the preloading time it will detect the time and
    by that will put the correct background?
    Thanks.

    var d:Date = new Date()
    var t:Number = d.getTime();
    You can also use: d.getHours(); d.getMinutes();
    d.getSeconds();
    Look up the Date class for further information.

  • Youtube Slow in the day and night.

    I've had the fios package for about 3 months now and i've got the Westell router not the Actiontec. For the first couple of months youtube videos have loaded very fast to my satisfaction, but up until now for about 4 weeks and going, youtube videos have been stopping to buffer every second, even the crappy quality videos.
    But the thing is its happening during the daytime and night time until 10 pm, after that the videos load extremely fast. But admittedly I have never stayed up to see when the slow down begins again the next day.
    So what do you fellow fios users think is the problem.

    actually that is one of the things that Verizon has going for it above other companies. They dont content filter.
    That is why tracerts are so important. they tell us where the possible bottlenecks or slowdowns may be occuring. In the case of MarkyMark there, the tracert told us that the problem is between the computer and router. We know with a great deal of certanty that the problem is one of 3 things, computer, cable, or router.
    Now for Markmc, we would need a tracert from you as well before any determinations can be made. Since both you and your friend are having similar issues with youtube, it could be a Verizon issue, or it could be an issue with a youtube server, or it could be a router inbetween Verizon and Youtube. A tracert would give us somewhere to start. I can connect to youtube just fine so it is likely to be an issue in your regional area. But it likely different than the one experianced by MarkyMark as his is a problem inside his house.
    Message Edited by spacedebris on 08-19-2009 09:59 AM
    ====================================================================================
    Error exists between keyboard and chair.

Maybe you are looking for

  • FV50-Park a G/L Account Document BDC Warning message in screen 1001

    I need some help with a BDC program.  I am working on a BDC program to process transaction FV50.   I went to SHDB and created a recording macro. When I test the recording with u201Csimpleu201D information the recording works correctly and the documen

  • My HP Color LaserJet 3600n won't install on new laptop running internet explorer 11 windows 8

    HP3600n was installed on old Gateway desktop and was accessed wirelessly from Dell laptop with Windows XP. I purchased new Lenovo laptop with internet explorer 11, Windows 8.1. I am unable to access HP3600n wirelessly for some reason. I tried to inst

  • Issue telated to STO return invoice

    hi expert, 1) user have created PO then created delivery then Invoice. now user have created return delivery and when user try to bill the return quentity. system give error" sales organisation is not define" so guid me where to check and its transec

  • Problem clicking on links to emails

    Not that computer literate I'm afraid but the only way I can explain the problem: When people put a link rather than their email address , when I click on it I just get a box with Firefox trying to download...As I use Firefox , I just don't get it. I

  • I want my serial number

    I bought Photoshop CS5 Extended Teacher/Student edition 3 days ago. It has been nothing but problem after problem. First off, they sold me a Mac instead of a Windows version. Now I wasn't too upset about that because they gave me the windows version.