question

technette avatar image
technette asked

Date Range between 1 and 3 days

Hi! I'm using the following to pull data for the next day. Now the requirement is to include data for the next three days. I also have to fields that must be evaluated. How do I do a query for date ranges between 1 and 3 days incorporating the two fields? There are other fields that will be evaluated. I'm mainly concerned with the two date fields first. (CONVERT(VARCHAR, CLD.FIRST_Date, 112) = CONVERT(VARCHAR, DATEADD(day, 2, GETDATE()), 112)) or (CONVERT(VARCHAR, CLD.SECOND_Date, 112) = CONVERT(VARCHAR, DATEADD(day, 2, GETDATE()), 112))
date-range
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
KenJ avatar image
KenJ answered
What version of SQL Server? Here is varchar: convert(varchar, cld.first_date, 112) between convert(varchar, getdate(), 112) and convert(varchar, getdate() + 2, 112) OR convert(varchar, cld.second_date, 112) between convert(varchar, getdate(), 112) and convert(varchar, getdate() + 2, 112) You can also use date if you have a newer version of SQL Server: convert(date, cld.first_date) between convert(date, getdate()) and convert(date, getdate() + 2) OR convert(date, cld.second_date) between convert(date, getdate()) and convert(date, getdate() + 2)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.