Php to compare the date size of two strings

Source: Internet
Author: User
Tags date1
This article mainly introduces how to compare the date size of two strings in php, involving related skills in php date operations, for more information about how to compare the date and size of two strings in php, see the following example. Share it with you for your reference. The details are as follows:

<? Phpfunction dateBDate ($ date1, $ date2) {// whether date 1 is greater than date 2 $ month1 = date ("m", strtotime ($ date1 )); $ mon2nd = date ("m", strtotime ($ date2); $ day1 = date ("d", strtotime ($ date1 )); $ day2 = date ("d", strtotime ($ date2); $ year1 = date ("Y", strtotime ($ date1 )); $ year2 = date ("Y", strtotime ($ date2); $ from = mktime (0, 0, 0, $ month1, $ day1, $ year1 ); $ to = mktime (0, 0, 0, $ mon2, $ day2, $ year2); if ($ from> $ ){ Return true;} else {return false; }}?> $ Date1 = "2009-10-13"; $ date = mktime (0, 0, 0, date ("m", strtotime ($ date1), date ("d ", strtotime ($ date1), date ("Y", strtotime ($ date1 )));

Finally, get the Unix timestamp $ date = 1255392000 for a date.

In most cases, the search time cannot be greater than the current date. The comparison function is written in the same way as the previous function, as shown below:

Function dateBCurrent ($ date) {// whether the date is greater than the current date $ currentDate = date ("Y-m-d "); // Obtain the current date $ cYear = date ("Y", strtotime ($ currentDate); $ cMonth = date ("m", strtotime ($ currentDate )); $ cDay = date ("d", strtotime ($ currentDate); $ year = date ("Y", strtotime ($ date )); $ month = date ("m", strtotime ($ date); $ day = date ("d", strtotime ($ date); $ currentUnix = mktime (0, 0, 0, $ cMonth, $ cDay, $ cYear); // Unix timestamp of the current date $ dateUnix = mktime (, 0, $ month, $ day, $ year ); // Unix timestamp of the date to be compared if ($ dateUnix <= $ currentUnix) {return true;} else {return false ;}}

I hope this article will help you with php programming.

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.