Quote:
Originally Posted by ownedbycats
Question: What would be the best way to take an integer (say, from days_between) and then turn that into "x years, x months, x days"?
I started trying to make a template using fractional_part and I think multiply but it didn't come out right. 
|
The biggest problem is that years and months are not fixed length. Is the year a leap year? How many days are in the month?
If you are willing to fix the number of days in a year to 360 and the number of days in a month to 30 then the computation is easy.
days= whatever;
years = floor(days/360);
months = floor (mod(days, 360)/30);
days = days - ((years*360) + (months * 30))