3

I am storing the start and end date of a users holiday period in a MySQL table.

I need to enable the ability for administrators to run reports where they specify two dates and all users who's start date or end date fall in between the two specified dates are retrieved from the database.

Has anyone done anything similar, or know of a good method of doing this?

JHamill
  • 145
  • 2
  • 4
  • 12
  • Possible Dupe of [#2736784](http://stackoverflow.com/questions/2736784/how-to-find-the-dates-between-two-dates-specified) (assuming PHP solution) – drudge Apr 13 '11 at 22:18
  • 1
    There is nothing about php in your question. Is the `php` tag of importance? – Eliasdx Apr 13 '11 at 22:19
  • @Eliasdx Apologies for that, I should have specified in the question that I was using PHP. – JHamill Apr 13 '11 at 22:50

3 Answers3

6

use mysql's between operator

Galen
  • 29,976
  • 9
  • 71
  • 89
1

if you want between two dates you can do:

`date` >= '$from' AND `date` <= '$to'

in the WHERE statement of the msql

Naftali
  • 144,921
  • 39
  • 244
  • 303
1
"SELECT * FROM table WHERE vac_start_date <= " . $search_end_date . " AND vac_end_date >= " . $search_start_date;

That should do it for you.

JLZenor
  • 1,460
  • 2
  • 14
  • 23