开发者

MySQL: Who are today "on" between 2 different dates

开发者 https://www.devze.com 2022-12-14 22:29 出处:网络
I have a Mysql problem. (I use PHP with it). For example I have this kind of database: Name| Started and | will end

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 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`
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号