skidmark10 Posted August 8, 2011 Share Posted August 8, 2011 Hello, I am using an html form where users submit their date of birth into a column in my mysql table. I am using phpmyadmin. I also have a table for current age that should get the users current age based on the information they submitted into the "date of birth" column. What date function would allow me to do the above? Also, where would I put that function? Again, I am using phpmyadmin. Quote Link to comment https://forums.phpfreaks.com/topic/244266-current-age-and-date-function-phpmyadmin/ Share on other sites More sharing options...
Pikachu2000 Posted August 8, 2011 Share Posted August 8, 2011 What do you mean you're using phpMyAdmin? How does a user enter anything in your database through phpMyAdmin? Quote Link to comment https://forums.phpfreaks.com/topic/244266-current-age-and-date-function-phpmyadmin/#findComment-1254551 Share on other sites More sharing options...
skidmark10 Posted August 8, 2011 Author Share Posted August 8, 2011 What do you mean you're using phpMyAdmin? How does a user enter anything in your database through phpMyAdmin? I'm sorry, forgot to mention that I have an html form that posts data into the mysql table. phpmyadmin is what I'm using for my database. Quote Link to comment https://forums.phpfreaks.com/topic/244266-current-age-and-date-function-phpmyadmin/#findComment-1254558 Share on other sites More sharing options...
Pikachu2000 Posted August 8, 2011 Share Posted August 8, 2011 I must say, it still isn't particularly clear what it is you want to do here, but if I've interpreted it right, you want to store the user's age in a separate table, based on their date of birth? If that's the case, there's really no need to store that when the data is already there to calculate the value. All you need is the right query to do it. Where `dob` is the DATE() or DATETIME() field with the birth date, and `table` is your table. SELECT ((DATE_FORMAT(NOW(),'%Y') - DATE_FORMAT(`dob`,'%Y')) - (DATE_FORMAT(NOW(),'00-%m-%d') < DATE_FORMAT(`dob`,'00-%m-%d'))) AS age FROM `table` Quote Link to comment https://forums.phpfreaks.com/topic/244266-current-age-and-date-function-phpmyadmin/#findComment-1254566 Share on other sites More sharing options...
The Little Guy Posted August 9, 2011 Share Posted August 9, 2011 Here is a quicker way: select (datediff(now(), '1986-07-22') / 365.25) as age; Quote Link to comment https://forums.phpfreaks.com/topic/244266-current-age-and-date-function-phpmyadmin/#findComment-1254941 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.