find difference between two date using php

find difference between two date using php

In This Post we are writing tutorial for finding difference between two date using php.
We can find difference between two date easily in php using some pre define functions.

<?php 
$date1 = "1999-06-19";
$date2 = "2016-01-27";
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

echo "Year = ".$years." Month = ".$months." Days= ".$days;

?<

Output is look like that

Years = 16 Months = 07 Days = 16
About Author

My name is Mukesh Jakhar and I am a Web Application Developer and Software Developer, currently living in Jaipur, India. I have a Master of Computer Application in Computer Science from JNU Jaipur University. I loves to write on technology and programming topics. Apart from this, I love to travel and enjoy the beauty of nature.

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.