date - How to Calculate duration 01-01-2016 to 31-01-2016 . get answer 1 month in PHP -


calculate between 2 dates duration in php

example :

start date : 01-01-2016

end date : 31-01-2016

i answer 30 days want result 1 month

more examples:

01-01-2016 31-01-2016 = 1 month

01-02-2016 29-02-2016 =1 month

01-03-2016 31-03-2016 =1 month

show on ..

<?php $date1 = '2000-01-20'; $date2 = '2000-02-20';  $ts1 = strtotime($date1); $ts2 = strtotime($date2);  $year1 = date('y', $ts1); $year2 = date('y', $ts2);  $month1 = date('m', $ts1); $month2 = date('m', $ts2);  echo $diff = (($year2 - $year1) * 12) + ($month2 - $month1); ?> 

i think you.


Comments