PHP mysql_query - 使用当前日期获取当前行的行

时间:2011-04-25 18:44:27

标签: php mysql

我有一个mysql表如下:

week    start_date  end date
1   2011-04-25  2011-05-01
2   2011-05-02  2011-05-08
3   2011-05-09  2011-05-15

我想运行一个查询来获取当前日期在指定周的start_date和end_date之间的周数。

3 个答案:

答案 0 :(得分:2)

SELECT week
FROM table_name
WHERE CURRENT_DATE() BETWEEN start_date AND end_date 

CURRENT_DATE() CURDATE()的同义词。

答案 1 :(得分:1)

SELECT week FROM TABLE_NAME WHERE CURDATE() BETWEEN start_date AND end_date;

答案 2 :(得分:0)

非常简单:

SELECT week FROM my_table WHERE CURRENT_DATE > start_date AND CURRENT_DATE <= end_date