Solved

calculate age based on birthdate

Posted on 2011-03-19
4
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 41

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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