Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Server check if time between times

I’m trying to run this query that check if the current time not between 19:00:00 and 02:00:00 (next day)

if (select convert(nvarchar (8), getdate(), 114)) not between '19:00:00' and '02:00:00' 
begin 
    print 'a' 
end

It’s not working when the time is after 00:00:00

Why?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks

>Solution :

IF NOT 
(
  (select convert(nvarchar (8),getdate(),114)) between '00:00:00' and '02:00:00'  
  OR 
  (select convert(nvarchar (8),getdate(),114)) between '19:00:00' and '23:59:59.999' 
)
   print 'a'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading