- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP program to compare two dates
To compare two dates in PHP, the code is as follows −
<?php $date_1 = new DateTime("2020-11-22"); $date_2 = new DateTime("2011-11-22"); if ($date_1 > $date_2) echo $date_1->format("Y-m-d") . " is later than ". $date_2->format("Y-m-d"); else echo $date_1->format("Y-m-d") . " is before " . $date_2->format("Y-m-d"); ?>
2020-11-22 is later than 2011-11-22
Two dates of ‘DateTime’ format are generated and checked to see which one is sooner or later. If the first date is later, relevant message is printed on the console. Otherwise, a message indicating that the first date is sooner than the second date is printed on the console.
- How to compare two Dates in C#?
- How to compare two dates in Java?
- Comparing two dates in PHP
- How to compare two dates in String format in Java?
- How to compare two dates along with time in Java?
- Compare Dates in Java
- Return all dates between two dates in an array in PHP
- PHP program to compare float values
- Java Program to Compare Two Strings
- Java Program to compare two sets
- PHP program to find the total number of date between any two given dates
- Java Program to compare two Byte Arrays
- Java Program to compare two Boolean Arrays