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 :.....