Jump to content

Current Age and Date function? phpmyadmin


skidmark10

Recommended Posts

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.

 

 

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.

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`

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.