downah Posted March 13, 2012 Share Posted March 13, 2012 Hi guys, My apologies if this is in the wrong forum but I am not really sure how to go about this. I have not written any code for this but I have four fields in one table one called age and 3 others dobmonth / dobday /dobyear - My question being how would I write some code that automatically fills in the age field based on the date of birth fields? If anyone could point me in the right direction that would be awesome, Appreciated. Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted March 13, 2012 Share Posted March 13, 2012 They use to have a good tutorial here at freaks, the link is somewhere on the front page or there about Quote Link to comment Share on other sites More sharing options...
scootstah Posted March 13, 2012 Share Posted March 13, 2012 Well for one, you should only have one database column for date of birth. Make it of DATE type. This way you can easily work with the data and it makes queries easier. Secondly, what does your age field look like? Quote Link to comment Share on other sites More sharing options...
downah Posted March 13, 2012 Author Share Posted March 13, 2012 I was using a date before but does it not require users to use dd/mm/yyyy ? I now have 3 selects which nicely lets user select the month day and year, is this possible to put into one date field? if so enlighten me! Back to the main question my age field at the moment is in the same table as the dob fields and it is an int. - or is this not what you meant? to floridaflatlander Is this tutorial about this certain question or similar? if so I will have a look Thanks for the help so far guys! Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 13, 2012 Share Posted March 13, 2012 You can concatenate the month, day, year and separators to create a variable to insert into your table date field. Then you can use http://www.zoomcities.com/forum/showthread.php?tid=5728 Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted March 13, 2012 Share Posted March 13, 2012 Is this tutorial about this certain question or similar? if so I will have a look Similar http://www.phpfreaks.com/tutorial/working-with-dates-in-php Quote Link to comment Share on other sites More sharing options...
RobertP Posted March 13, 2012 Share Posted March 13, 2012 function getAgeFromTime($time,$today = null){ if(!$today) $today = time(); $age = date('Y',$today)-date('Y',$time); if(date('m.d',$today)<=date('m.d',$time)) $age--; return $age; } Quote Link to comment Share on other sites More sharing options...
downah Posted March 13, 2012 Author Share Posted March 13, 2012 Thanks a lot for the timediff() I think that will help, and it makes sense to store the 3 selects into one variable and to send that through to the server, thanks for the input! to robertP I keep reading over the code you wrote and understand it considerably but would it be able for you to explain me how to use that in action? Appreciated Quote Link to comment Share on other sites More sharing options...
downah Posted March 14, 2012 Author Share Posted March 14, 2012 You can concatenate the month, day, year and separators to create a variable to insert into your table date field. Then you can use http://www.zoomcities.com/forum/showthread.php?tid=5728 I have now concatenated the 3 fields into one variable which goes into a date field (dob) 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.