- Instant help with your Php coding problems

Get the number of days between two dates in PHP

Question:
How to get the number of days between two dates in PHP?
Answer:
$startDate = new DateTime("2019-10-27");
$endDate = new DateTime("2020-04-11");

$difference = $endDate->diff($startDate);
echo $difference->format("%a");
Description:

To get the difference between two dates first you need to create a start date and an end date DateTime objects. Afterward, simply use the diff method on the end date and use the start date as a parameter. The end result is a DateInterval object that can be formatted to as you want.  

Share "How to get the number of days between two dates in PHP?"