R0bb0b Posted October 10, 2008 Share Posted October 10, 2008 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. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 10, 2008 Share Posted October 10, 2008 Check this out: http://www.phpfreaks.com/forums/index.php/topic,219477.0.html You should be able to use the function that I wrote and modify it to also return the months. Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 10, 2008 Author Share Posted October 10, 2008 That should do it, thank you. Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 10, 2008 Author Share Posted October 10, 2008 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 I just divided days by 30.4 which is as accurate as I need to be for this project. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 10, 2008 Share Posted October 10, 2008 That'll work. This will also get you the leapyear: <?php $leapyear = date('L') ? 366 : 365; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.