Home >Backend Development >PHP Tutorial >Can comparison operators be used on dates and times?

Can comparison operators be used on dates and times?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-06 13:53:58976browse

Can the following code return "true" or "false"?

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

I compiled a code for sending text messages, which is used to retrieve the database. If the scheduled sending time is earlier than the current time, the text message will be sent.
If the above code does not work, please recommend a method, thank you!
(Beginners, the questions may be a bit idiotic, please answer patiently, thank you)

Reply content:

Can the following code return "true" or "false"?

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

I compiled a code for sending text messages, which is used to retrieve the database. If the scheduled sending time is earlier than the current time, the text message will be sent.
If the above code does not work, please recommend a method, thank you!
(Beginners, the questions may be a bit idiotic, please answer patiently, thank you)

<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>

Can strings be compared in size? . .

strottime() Okay

Shouldn’t it be a timestamp comparison

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