My NOW Function is not working the way I want it to. I just want to simply find dates that are past todays date.
Here is my query.
SELECT *
FROM `trade_show_inventory`
LEFT JOIN `trade_show_reserved`
ON `trade_show_inventory`.`id` = `trade_show_reserved`.`productid`
WHERE `trade_show_inventory`.`quantity` > 0
OR `trade_show_reserved`.`datereserved`
+ INTERVAL 5 day <= '2013-03-31'
AND `trade_show_reserved`.`datereserved` > Now()
EDIT:
I changed my query to this and it still is not working. Still working away at it..
$date = date('Y-m-d');
$sql = "SELECT * FROM `trade_show_inventory` LEFT JOIN `trade_show_reserved`
ON `trade_show_inventory`.`ID` = `trade_show_reserved`.`ProductID`
WHERE (`trade_show_inventory`.`Quantity` > 0)
or (`trade_show_reserved`.`DateReserved` + INTERVAL 5 DAY <= '$setupStart' and
`trade_show_reserved`.`DateReserved` > '2013-03-25')";
Well, your where
clause is parsing like:
WHERE (`trade_show_inventory`.`Quantity` > 0) or
(`trade_show_reserved`.`DateReserved` + INTERVAL 5 DAY <= '2013-03-25' and
`trade_show_reserved`.`DateReserved` > NOW()
)
If the date is five days before 2013-03-25, then it can't be in the future (as of today at least).
Put parentheses around the where
clauses to get the logic you intend.
NOW() doesn't return a date... it's a complete timestamp:
mysql> select NOW();
+---------------------+
| NOW() |
+---------------------+
| 2013-03-25 17:20:06 |
+---------------------+
1 row in set (0.00 sec)
Try wrapping the DATE function around it:
mysql> select DATE(NOW());
+-------------+
| DATE(NOW()) |
+-------------+
| 2013-03-25 |
+-------------+
1 row in set (0.00 sec)
NOW()
returns the current date & time.
You would perhaps want to use DATE()
as it returns the date without time.
NOW()函数使用时间戳,我认为您应该首先将其转换为所需的日期格式。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.