Jump to content

[SOLVED] age in years and months


R0bb0b

Recommended Posts

I can calculate age in years very easily but I also need months too.  For example 39yrs and 5mos old.  I would rack my own head against the wall for a while but unfortunately I am currently pressed for time and would like to know if anybody can point out a function that will do this.  Much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/127868-solved-age-in-years-and-months/
Share on other sites

Actually decided to use this function:

http://us3.php.net/manual/it/function.mktime.php#86086

which returns an array of months, days, and a year in decimal format.

 

I'm also using this line to take into account leapyear:

<?php $leapyear = date('L', mktime(0, 0, 0, 1, 1, date("Y"))) ? 366 : 365; ?>

 

Thought about the different values for months in a year and figuring out which month to start counting from and etc... etc... and said :P

 

I just divided days by 30.4 which is as accurate as I need to be for this project.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.