1

This is a bit like the popular relative time (ago) except I'm not dealing with a timestamp but the number of months.

I'm not sure on how to go by this though?

Heres some examples to improve your understanding of my question:

If input was:

3

Output would be:

3 Months

If input was:

13

Output would be:

1 Year, 1 month

So for every 12 months its X Year(s) (if any) and then the remaining months are following it with X month(s).

Dharman
  • 30,962
  • 25
  • 85
  • 135
user962026
  • 207
  • 1
  • 5
  • 12

1 Answers1

1

You can use the mod operator to get remaining months:

$years = (int)($total_months / 12);
$months = $total_months % 12;
Dharman
  • 30,962
  • 25
  • 85
  • 135
Godwin
  • 9,739
  • 6
  • 40
  • 58