views:

47

answers:

2

I have a Mysql problem. (I use PHP with it).

For example I have this kind of database:

Name | Started and | will end
Jason | 2009-12-17 | 2009-12-24
Ericke | 2009-12-12 | 2009-12-30
Maria | 2010-01-02 | 2010-01-10

With mysql (or php) question I would like to get the names of people, which are "on" right now (2009-12-19).

The answer should be:
Jason
Ericke

Thank you for your great help in advance!

+1  A: 

what about a query in which you compare dates ?

Something like this, I suppose, should do :

select name
from your_table
where started <= curdate() 
    and will_end >= curdate()

Notes :

  • You'll need to adjust the table and columns names, of course
  • and maybe you'll want to use > and < instead of >= and <= ; depends on your data.
  • I use the curdate() function, which gets the date of the current day -- I like it better than injecting the date into the query using some PHP code.
Pascal MARTIN
Thank you for your great help!!!
jsk
You're welcome :-) Have fun !
Pascal MARTIN
+2  A: 
SELECT *
  FROM `table`
 WHERE CURDATE() BETWEEN `startdate` AND `enddate`
knittl