简体   繁体   English

PHP MySQL日期大于

[英]PHP MySQL date greater than

Ok... 好...

So I have a string which in this case checks the date with the PHP date('Ymd H:i:s'); 所以我有一个字符串,在这种情况下,它将用PHP date('Ymd H:i:s');检查日期。 I want this to check with a database row, if it's larger than. 我要检查数据库行是否大于。

$sql="SELECT * FROM date WHERE '$this->dateClose' < start_time AND '$this->dateOpen' < end_time";

It's in a loop so it will print everything which has a start_time less than dateClose and the opposite for dateOpen and end_time. 它处于循环中,因此它将打印start_time小于dateClose且dateOpen和end_time相反的所有内容。 But it doesn't work, please help. 但这不起作用,请帮助。

尝试使用WHERE field operator value_to_match并以正确的格式更改值以匹配datetime

$sql="SELECT * FROM date WHERE start_time > '".date('Y-m-d H:i:s', strtotime($this->dateClose))."' AND end_time < '".date('Y-m-d H:i:s', strtotime($this->dateOpen))."'";

请尝试这个

$sql="SELECT * FROM date WHERE '".$this->dateClose."' < start_time AND '".$this->dateOpen."' < end_time";

For the given values 对于给定的值

start_time = 2014-11-01 21:00 end_time = 2014-11-02 19:00 
$this->dateOpen = 2014-11-01 20:00 $this->dateClose = 2014-11-02 18:00

geting no rows from sql is OK. 从sql获取任何行都可以。 There is no valid row for your condition 没有符合您条件的有效行

WHERE '2014-11-02 18:00' < start_time AND '2014-11-01 20:00' < end_time'

the '2014-11-02 18:00' < '2014-11-01 21:00' part is false. '2014-11-02 18:00' < '2014-11-01 21:00'部分为假。 You have to rethink what you want to get from your sql. 您必须重新考虑要从sql获取的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM