tags:

views:

25

answers:

2

For example, I have the month 13 and I want to convert it to 1 year and 1 month with php. 26 - 2 years and 2 months. How to "convert" it?

+2  A: 

Divide by 12 and take integer part and modulus separately.

FractalizeR
i tried this.Number 16 - 1.333(3).But it's 1 year and 4 months
lam3r4370
+3  A: 
$totalmonths = 26;
$years = floor($totalmonths/12);
$months = $totalmonths % 12;
echo $years, " year", $years==1?"":"s";
if ($months != 0)
    echo " and ", $months, "month", $months==1?"":"s";
Artefacto
This works.Thank You very much!
lam3r4370