A few questions

Source: Internet
Author: User
Why is this echo error ;? Php $ date1 = & quot; Apr/13/2012 & quot; $ date2 = & quot; Apr/6/2012 & quot; if ($ date1 & gt; $ date2) {echo & quot; correct
Why is this echo error?
$ Data 1 = "Apr/13/2012 ";
$ Data 2 = "Apr/6/2012 ";
If ($ date1> $ date2 ){
Echo "correct ";
} Else {
Echo "error". "script" alert ('error'); script ";
}

?>

------ Solution --------------------
You are comparing strings, not numbers. The first character of $ date1 and $ date2 is "1" and "6 ".
The ascii code of "1" is smaller than that of "6". of course, date1> date2!

Convert a string to a timestamp (strtotime) before comparison)

PHP code
  Strtotime ($ date2) {echo "correct";} else {echo "error". "script" alert ('error'); script ";}?>
------ Solution --------------------
The size of the string does not seem to be comparable !!
------ Solution --------------------
The standard time format is not written like this: Apr/13/2012
This should be the case: Apr 13 2012
This type: 4/13/2012
Or this:
Or :.....

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.