Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SQl date script help Expand / Collapse
Author
Message
Posted Thursday, March 21, 2013 7:19 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Sunday, August 17, 2014 3:50 AM
Points: 329, Visits: 858
I need to check if days are Sat, Sun and Mon and time between Sat 6am to Monday 6am. Can you please help?

I am trying something like this but I am stuck..

IF datepart(dw, getdate()) IN (1,7,2)
AND (datepart(hour,getdate()) Between 6 AND ....)
Post #1434108
Posted Friday, March 22, 2013 1:54 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 8:36 AM
Points: 3,086, Visits: 3,322
You may need to check the servers this runs on for what @@datefirst is otherwise a quick stab at this is:-

IF DATEPART(dw, GETDATE()) = 1-- any time on Sunday
OR ( DATEPART(dw, GETDATE()) = 7
AND DATEPART(hour, GETDATE()) > 5
) -- after 6 a.m. Saturday
OR ( DATEPART(dw, GETDATE()) = 2
AND DATEPART(hour, GETDATE()) < 6
) --before 6 a.m. Monday
BEGIN
PRINT 'Criteria correct'
END

But you need to check this as my server settings are different to yours


-------------------------------
Posting Data Etiquette - Jeff Moden
Smart way to ask a question

There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
Post #1434151
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse