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

Can comparison operators be used on dates and times?

WBOY
Release: 2016-07-06 13:53:58
Original
946 people have browsed it

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

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

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>
Copy after login
Copy after login

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>
Copy after login

Can strings be compared in size? . .

strottime() Okay

Shouldn’t it be a timestamp comparison

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template