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-10With 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 ErickeThank you for you开发者_如何学Pythonr great help in advance!
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.
SELECT *
FROM `table`
WHERE CURDATE() BETWEEN `startdate` AND `enddate`
精彩评论