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

Can comparison operators be used on dates and times?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:53:58
Original
988 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)

//可以,不过可以用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
Copy after login

Can strings be compared in size? . .

strottime() Okay

Shouldn’t it be a timestamp comparison

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template