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.

 

 

Link to comment
Share on other sites

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`

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.