Let's say: $termdate = 9/10/11 $addeddate = 8/11/11 $nowdate = 9/23/11 The result is calculated at 13 days diff and $newtermdate will be 09/23/11. That is fine. However let's say: $termdate = 12/09/11 $addeddate = 8/11/11 $nowdate = 9/23/11 The result is still calculated at 13 days diff and $newtermdate will be 12/22/11. That is obviously wrong. Any ideas? $termdate = $row['termdate']; $addeddate = $row['date']; $nowdate = date("m/d/y"); $diff = abs(strtotime($nowdate) - strtotime($addeddate)); $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)); $newtermdate = strtotime('+'.$days.' day', strtotime($termdate)); $newtermdate = date('m/d/y', $newtermdate); PHP:
Try setting your dates as strings instead of pulling them from the database. See if it works as expected. If so, there may be a problem with the data you are pulling from the database. $termdate = '2011-09-10'; $addeddate = '2011-08-11'; $nowdate = date("m/d/y"); $diff = abs(strtotime($nowdate) - strtotime($addeddate)); $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)); $newtermdate = strtotime('+'.$days.' day', strtotime($termdate)); $newtermdate = date('m/d/y', $newtermdate); echo $newtermdate; PHP:
Why is 12/22/11 not 13 days later than 12/9/11? 9 + 13 = 22 the last time I looked. Did I miss something? (You're using m/d/y format.)