Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

calculate age based on birthdate

Posted on 2011-03-19
4
Medium Priority
?
504 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

926 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