Check if the current date is between two dates + m

2019-01-22 21:31发布

I have following table :

id     dateStart     dateEnd      active
1      2012-11-12    2012-12-31   0
2      2012-11-12    2012-12-31   0

I want to compare todays date in between dateStart and dateEnd.

Following is my query for this :

$todaysDate="2012-26-11";
$db = Zend_Registry::get("db");
$result = $db->fetchAll("SELECT * FROM `table` WHERE active=0 AND {$todaysDate} between dateStart and dateEnd");
return $result;

But its not working. Any solution. Thanks in advance.

5条回答
Anthone
2楼-- · 2019-01-22 22:05
$todaysDate="2012-11-26";//changed date
$db = Zend_Registry::get("db");
$select=$db->query("SELECT * FROM `table` WHERE active=0 AND {$todaysDate} between dateStart and dateEnd");
$result = $select->fetchAll();
return $result;  
查看更多
我命由我不由天
3楼-- · 2019-01-22 22:06
$sql = mysql_query("SELECT * FROM register WHERE CURDATE() between reg_start_date and reg_end_date") or die(mysql_error());
查看更多
孤傲高冷的网名
4楼-- · 2019-01-22 22:09

You needed to put single quotes around the changed date:

"SELECT * FROM `table` WHERE active=0 AND '{$todaysDate}' between dateStart and dateEnd"
查看更多
放我归山
5楼-- · 2019-01-22 22:13

MySQL uses YYYY-MM-DD by default:

$todaysDate="2012-26-11";

should be:

$todaysDate="2012-11-26";

And you need single quotes around it in the query.

查看更多
Animai°情兽
6楼-- · 2019-01-22 22:22

Try this :: This will solve your problem

SELECT * FROM `table` WHERE active=0 AND CURDATE() between dateStart and dateEnd
查看更多
登录 后发表回答