Converting a floating value to Months and days

Viewed 107

Just wondering if anyone knows how to convert a floating value to months and days. For example if I ended with 25.6 as a floating value. I want to convert the 25 part into months (25 months) and 0.6 part in days (something like 17 days)

 val = 25.6
 md = monthday(val)
 #out >  (1.0, 25.6)

I tried the monthday function but its results seem to be not what I am after. Next, I want to add it into some DateTime value such as today() + md

1 Answers
julia> function f(x)
           fm, m = modf(x)
           Day(Int(round(30.416*fm))) + Month(Int(m))
       end
f (generic function with 1 method)

julia> f(25.6)
25 months, 18 days
Related