How to compare the date and time in php

Source: Internet
Author: User
Comparison of date and time in php I remember that in php, the date and time strings can be directly compared to the size, for example, & quot; 2011-11-2:58:18 am & quot; & lt; & quot; 2011-11-am & quot;, I remember that php can be used like this, but today I encountered a problem and always compared the date and time comparison in php.
I remember that in php, the date and time strings can be directly compared, for example, "9:58:18 am" <"10:00:00 am". remember that php can be used like this, however, if you encounter a problem today, the comparison result is always incorrect. Finally, change it to strtotime ("9:58:18 am") <strtotime ("10:00:00 am") to compare the timestamp size.

------ Solution --------------------
Where does PHP say that the time can be directly compared with the size ???

This is just a string comparison.
"2011-11-21 9:58:18 am" <"2011-11-21 10:00:00 am"
No
"2011-11-21 09:58:18 am" <"2011-11-21 10:00:00 am"

The correct time comparison means that after strtotime is converted to a unix timestamp
------ Solution --------------------
The database can directly compare the processing methods of. php during the time period to convert them into timestamps, which is simple, convenient, and convenient.
------ Solution --------------------
In php, change to the number of seconds for comparison.
------ Solution --------------------
Posting rate: 0%
Total posts: 6
Normal close: 0

Who will reply to this posting rate?
------ Solution --------------------
Strtotime conversion is the correct idea, otherwise it can only be separated and compared.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.