php Object of class DateInterval could not be converted to string
You need to call DateInterval::format() to display that difference as a string. echo $diff->format(‘%d days’); See the manual for all of the available formatting options.
You need to call DateInterval::format() to display that difference as a string. echo $diff->format(‘%d days’); See the manual for all of the available formatting options.
Start by defining some test cases, then you will see that the function is very simple and needs no loops from datetime import datetime def diff_month(d1, d2): return (d1.year – d2.year) * 12 + d1.month – d2.month assert diff_month(datetime(2010,10,1), datetime(2010,9,1)) == 1 assert diff_month(datetime(2010,10,1), datetime(2009,10,1)) == 12 assert diff_month(datetime(2010,10,1), datetime(2009,11,1)) == 11 assert diff_month(datetime(2010,10,1), datetime(2009,8,1)) … Read more