Solved

calculate age based on birthdate

Posted on 2011-03-19
4
493 Views
Last Modified: 2012-05-11
Hi experts,

I need to calculate an age in (My)SQL based on a date stored in a varchar field (format example 1962-5-21).

The age calculation should be accurate to the day.

And no the varchar type of field can not be changed to dateformat!

Can this still be done?

Thanks

0
Comment
Question by:Steynsk
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
JoeNuvo earned 500 total points
ID: 35171722
regardless of how to calculate age.
actually on MySQL, varchar can convert to datetime

for ex.
SELECT STR_TO_DATE('1962-5-21','%Y-%m-%d');

I will feed more comment if I'm found solution for age.
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35171759
try to read below link, see if you can adapt it to meet your requirement or not.

http://ma.tt/2003/12/calculate-age-in-mysql/#comment-486714

(reply from ALLAN on SEPTEMBER 28, 2010 @ 8:21 PM)
0
 
LVL 40

Expert Comment

by:Sharath
ID: 35174092
Did you try datediff to get the age in days?

select datediff(curdate(),agecol) as age from agetab;

Open in new window

0
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 35178940
thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now