Heim  >  Artikel  >  Backend-Entwicklung  >  时间日期能够使用比较运算符吗?

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

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

下面的代码能够返回"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() 可以吧

不应该是时间戳比较嘛

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn