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

How to select data using getdate() + time?

I have this code:

select * 
from Table
where [Date] >= cast(getdate() - 1 as date) 
  and [Date] < cast(getdate() + 1 as date)
order by [Date] desc

and I need to change this part:

where [Date] >= cast(getdate() - 1 as date)

that the search start at 02:00 AM + getdate() – 1,

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

Something like this:

where [Date] >= getdate() - 1, 02:00:00

>Solution :

In SQL Server with the datetime type you can simply concatenate the time portion after first removing it. Try

where [Date] > DateAdd(dd, DateDiff(dd, 1, GetDate()), 0) + '02:00:00'
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