如何使用mysql检查日期是否在date1和date2之间? [英] How to check if a date is between date1 and date2 using mysql?
问题描述
我正在尝试编写一个查询,该查询将针对我在mysql/php中的表列date1和date2检查今天的日期.这是我想要的:
I'm trying to write a query that will check today's date against my table columns date1 and date2 in mysql/php.. This is what I'm after:
事件"表:
- date1 =开始日期(XXXX-XX-XX)
- date2 =结束日期(XXXX-XX-XX)
查询:
- 从2012年1月18日在date1和date2(或等于date1和date2)之间的事件中选择*
但是我不确定如何去做..任何帮助将不胜感激:)
But I'm not sure how to go about it.. any help would be appreciated :)
也许我不清楚..如果今天的日期='2012-01-18',我需要它来查找结果,如果今天的日期在date1和date2的日期范围之间.那么date1可能是'2012-01-04 'and date2可能是'2012-01-21'..因此,如果今天的日期介于这些日期之间或之日,则返回结果.
Maybe I was unclear.. if todays date = '2012-01-18' I need it to find results if today's date is between the date range of date1 and date2.. So date1 may be '2012-01-04' and date2 may be '2012-01-21'.. so if todays date falls between or on those dates, a result is returned..
推荐答案
SELECT * FROM events
WHERE date1<='2012-01-18'
AND date2>='2012-01-18'
这篇关于如何使用mysql检查日期是否在date1和date2之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!