ted_chou12 Posted December 30, 2006 Share Posted December 30, 2006 if my birthday is 2005-6-19, how do I get my age?I tried strtotime() and subtract the birthdate from the current date , but it doesnt work... i get a negative big number.Can anyone help me with this? thanksTed Link to comment https://forums.phpfreaks.com/topic/32299-solved-how-to-subtract-dates-to-get-age/ Share on other sites More sharing options...
michaellunsford Posted December 30, 2006 Share Posted December 30, 2006 The difference is in seconds. You'll have to do the math to figure out how many years, months, weeks, days, hours, seconds. Link to comment https://forums.phpfreaks.com/topic/32299-solved-how-to-subtract-dates-to-get-age/#findComment-149927 Share on other sites More sharing options...
ted_chou12 Posted December 30, 2006 Author Share Posted December 30, 2006 nope does work... that number is too small for my age as well. Link to comment https://forums.phpfreaks.com/topic/32299-solved-how-to-subtract-dates-to-get-age/#findComment-149934 Share on other sites More sharing options...
michaellunsford Posted December 30, 2006 Share Posted December 30, 2006 here's an approximation. The months is not going to be 100%. Someone has something better somewhere, you might have to dig.[code]<?php$date="12 March 1983";$total=time()-strtotime($date);$calc=array('years'=>60*60*24*365, 'months'=>60*60*24*30,'days'=>60*60*24,'hours'=>60*60,'minutes'=>60);do { if(current($calc)<$total) { echo floor($total/current($calc))." ".key($calc)."<br />\n"; $total=$total - floor($total/current($calc))*current($calc); }}while(next($calc));?>[/code] Link to comment https://forums.phpfreaks.com/topic/32299-solved-how-to-subtract-dates-to-get-age/#findComment-149955 Share on other sites More sharing options...
ted_chou12 Posted December 31, 2006 Author Share Posted December 31, 2006 thanks! :D Link to comment https://forums.phpfreaks.com/topic/32299-solved-how-to-subtract-dates-to-get-age/#findComment-150197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.