View Single Post
Old 03-26-2022, 12:58 PM   #361
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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))
chaley is offline   Reply With Quote