Solved

calculate age based on birthdate

Posted on 2011-03-19
4
497 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
myqsl update statement on phpMyAdmin 8 37
MS SQL Update query with connected table data 3 41
How to fix Datetime in MySQL? 4 51
Very Large data in MYSQL 7 75
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …

820 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