Comparing Dates in PHP: Handling Non-Zero Padded Days
You wish to compare current and stored dates that lack zero padding, such as "2011-10-2," to determine the greater one. The initial approach using "<" comparison may yield incorrect results. Here are alternative methods:
Method 1: Using strtotime()
If all dates in question are after January 1, 1970, you can utilize strtotime():
Method 2: Using DateTime Class (PHP 5.2.0 )
For PHP versions 5.2.0 and above, the DateTime class offers another approach:
The above is the detailed content of How to Reliably Compare Dates in PHP Without Zero Padding?. For more information, please follow other related articles on the PHP Chinese website!