php - Months to year(s) -


i wondering how can output in php number of years given amount of months.

for example:

i give 12 months. output is: 1 year

i give 6 months. output 6 months

i give 24 months. output 2 years

i give 18 months. output 1 year 6 months

i don`t have idea how approach this.

thanks!

what simple math operations ?

$input  = 16; $months = $input % 12; $years  = floor($input / 12); 

output:

$months = 4; $years  = 1; 

btw - in example have mistake - 16 months not equal 1 year , 6 months.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -