Skip to main content
Known Participant
April 25, 2012
Question

Today's Date within Date Range

  • April 25, 2012
  • 1 reply
  • 2814 views

I have a BeginDate and EndDate in a database.  I want to be able to list those records if todays date is within the date range of BeginDate and EndDate.  I am unsure of the coding on this.  Has anyone done this and can give me some help? Thanks.

This topic has been closed for replies.

1 reply

Owainnorth
Inspiring
April 25, 2012

Depends on the database platform as to exactly what function you'd use, but essentially:

SELECT cols

FROM table

WHERE now() > BeginDate

AND now < EndDate

That's all there is to it.

Some databases let you do BETWEEN clauses, so even neater

WHERE now() BETWEEN StartDate and EndDate.

Just be careful to do some testing as to what happens when today *is* the end or start date, you may want them included or excluded depending on your requirements.

Known Participant
April 25, 2012

Ok that makes sence. I am getting an error with  WHERE now() BETWEEN begindate and end_date

it says "now" is an invalid function.

Owainnorth
Inspiring
April 25, 2012

Right, so you need to find out what the correct function name is for your database platform.