How to compare two dates in PHP?

Posted by Editorial Staff | Updated on

Want to compare two dates in PHP? Store it in YYYY-MM-DD and then string comparison will work because ‘1’ > ‘0’, etc.

If you are using PHP 5 >= 5.2.0, you could use the DateTime class:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers