Home  >  Article  >  Backend Development  >  时间日期能够使用比较运算符吗?

时间日期能够使用比较运算符吗?

WBOY
WBOYOriginal
2016-07-06 13:53:58902browse

下面的代码能够返回"true"或"false"吗?

<code>$time<=date("Y-m-d-H-i-s")</code>

我编了一个短信发送的代码,作用是检索数据库,如果预定发送时间早于当前时间,就发送短信。
如果上面的代码不能起作用,请推荐一个方法,谢谢!
(初学者,问题可能有些白痴,请耐心回答,谢谢)

回复内容:

下面的代码能够返回"true"或"false"吗?

<code>$time<=date("Y-m-d-H-i-s")</code>

我编了一个短信发送的代码,作用是检索数据库,如果预定发送时间早于当前时间,就发送短信。
如果上面的代码不能起作用,请推荐一个方法,谢谢!
(初学者,问题可能有些白痴,请耐心回答,谢谢)

<code class="php">//可以,不过可以用strtotime转化比较
>>> $time=date('Y-m-d H:i:s')
=> "2016-06-10 13:39:38"
>>> $time >='2016-06-09 11:11:11'
=> true
>>> $time>='2016-06-19 11:11:11'
=> false
>>> strtotime($time)>=strtotime('2016-06-19 11:11:11')
=> false</code>

字符串可以比较大小么。。。

strottime() 可以吧

不应该是时间戳比较嘛

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn