SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQl date script help


SQl date script help

Author
Message
SQL_Surfer
SQL_Surfer
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1528 Visits: 1098
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 ....)
Stuart Davies
Stuart Davies
SSCertifiable
SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)

Group: General Forum Members
Points: 7155 Visits: 4814
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 questionThere 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search