Solved

calculate age based on birthdate

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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 …
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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