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. Link to comment https://forums.phpfreaks.com/topic/127868-solved-age-in-years-and-months/ 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. Link to comment https://forums.phpfreaks.com/topic/127868-solved-age-in-years-and-months/#findComment-662047 Share on other sites More sharing options...
R0bb0b Posted October 10, 2008 Author Share Posted October 10, 2008 That should do it, thank you. Link to comment https://forums.phpfreaks.com/topic/127868-solved-age-in-years-and-months/#findComment-662060 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. Link to comment https://forums.phpfreaks.com/topic/127868-solved-age-in-years-and-months/#findComment-662341 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; ?> Link to comment https://forums.phpfreaks.com/topic/127868-solved-age-in-years-and-months/#findComment-662349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.