Link to home
Start Free TrialLog in
Avatar of dev09
dev09

asked on

SQL Query - Date range filtering

Hi, i'm coding in PHP/MySQL and have the following table data, wondering how to achieve the following SQL queries...

TABLE: 'events'
id    title                   startDate                     finishDate       
1     do this                 01/09/2015 9:00 AM     30/09/2015 5:00 PM
2     do that            02/09/2015 9:30 AM       02/10/2015 5:30 PM
3     then this            10/10/2015 8:00 AM       11/11/2015 5:00 PM

SQL Search #1:
SELECT * FROM events WHERE (current time is in between `startDate` and `finishDate`)

Open in new window


SQL Search #2:
SELECT * FROM events WHERE (current month is inside of `startDate` and `finishDate`)

Open in new window


SQL Search #3:
SELECT * FROM events WHERE (current week is inside of `startDate` and `finishDate`)

Open in new window


Hope someone can shine some light.

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is a fairly common calendar problem.  You probably want to use the ISO-8601 standard representation for dates.  It will make all of your programming easier.  Here's how to do that.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial