php - Difference in UK Dates -


this question has answer here:

i trying show difference in days , months between 2 dates

$date1 = $start; $date2 = $end; $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));  printf("%d years, %d months, %d days\n", $years, $months, $days); 

however shows 0 years, 0 months, 0 days

the dates in $start , $end in format dd/mm/yyyy

as have stated within comment the dates in $start , $end in format dd/mm/yyyy. need first replace d-m-y using str_replace or datetime::createfromformat try using as

$date1 = str_replace('/','-',$start); $date2 = str_replace('/','-',$end); 

php date conversion strtotime


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -