Calculating age from date of birth

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Calculating age from date of birth
# 1  
Old 10-11-2010
Calculating age from date of birth

MySQL...

Given a column containing people's dates of birth, what's the best way to create a computed column giving their age in years...I can't find a suitable date/time function that'll do the job! Smilie
# 2  
Old 10-12-2010
int((Today - date_of_birth)/10000)
Both dates in yyyymmdd
# 3  
Old 10-12-2010
Thanks jgt...

This is what I've ended up with...
Code:
SELECT 
    date_format(DOB, '%d/%m/%Y') DOB , 
    convert((date_format(now(),'%Y%m%d') - date_format(DOB, '%Y%m%d'))/10000, unsigned) Age   
FROM
    table

Now, if only I understood why that works! What's the difference between subtracting formatted dates and unformatted dates? And why 10000? Smilie
# 4  
Old 10-12-2010
20101012 - 19500101 = 600911
int(600911/10000) = 60
20101012 - 19501011=60001
int(60001/10000)=60
20101012 - 19501013=599999
int(59999/10000)=59

Un-formatted dates are probably in the seconds since an epoch date. Depending on the source, this could be Jan 1 1970 ending in 2037 for 32 bit values.
# 5  
Old 10-13-2010
Thanks again jgt. It's obvious when you lay it out like that!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Age of file

Hi All.. Is there any easy way to find out how many days older is file? for ex. fileA 20 days fileB 10 days I am currently on AIX, and there is no STAT command available in this environment. What are my options? Thanks Abhijeet R (1 Reply)
Discussion started by: freakabhi
1 Replies

2. Shell Programming and Scripting

Calculating the epoch time from standard time using awk and calculating the duration

Hi All, I have the following time stamp data in 2 columns Date TimeStamp(also with milliseconds) 05/23/2012 08:30:11.250 05/23/2012 08:30:15.500 05/23/2012 08:31.15.500 . . etc From this data I need the following output. 0.00( row1-row1 in seconds) 04.25( row2-row1 in... (5 Replies)
Discussion started by: ks_reddy
5 Replies

3. Shell Programming and Scripting

Calculating expiry date using date,sed,grep

Hi, I would greatly appreciate it if someone can help me with my problem. I have a crawler which collects spam URLs everyday & this data needs to be published in a blacklist. Here's the catch: The "Time To Live" (TTL) for each URL is 3 months (or whatever for that matter). If i see the... (5 Replies)
Discussion started by: r4v3n
5 Replies

4. Shell Programming and Scripting

Calculating 7 days ago date for the given Argument

Hi I have shell script and I am facing the below issue to integrate the date calculation to the the script. If I give the $1 as the date(20110701) then I need to get the 7 days ago date for the same format.(20110624). At first I thought its a simple one to handle and I did a search in the... (10 Replies)
Discussion started by: filter
10 Replies

5. UNIX and Linux Applications

sqlite: calculating with dates - compare current date minus 6 months with stored record

Hi I have a table with name, date in format DD.MM.YYYY. I need to something like this (I try to explain in pseudo code) if SYSDATE (current date) minus 6 months > $expiry date print OK else print NOK with $name and $expiry date I know this is possible with Oracle. How to do this... (0 Replies)
Discussion started by: slashdotweenie
0 Replies

6. Shell Programming and Scripting

Calculating using date

I need to help to calculating using date in a script. One application is licensed by date, some month at a time. I can read the date from system and get an output like this: echo $status 6A34 System4 01.01.11-31.01.11 My goal is to use license date 31.01.11 and subtract todays date... (7 Replies)
Discussion started by: Jotne
7 Replies

7. Shell Programming and Scripting

Store date-of-birth as "1#7#0#2#" in file

Hello, My input files are having header/body/footer. The first three digits finds whether the data is header/body/footer. For example, 010AAAAA 20100507 234KB BBBBBBBBBB_20100506.DAT 020CCCCC DDDDDDDDD 373983983 19750426 456.90 ... (1 Reply)
Discussion started by: nvkuriseti
1 Replies

8. Shell Programming and Scripting

file age

How can I count the age of the file (e.g. in minutes)? (4 Replies)
Discussion started by: jarmo.leppanen
4 Replies

9. What is on Your Mind?

What is your age?

What is your age? (15 Replies)
Discussion started by: royal
15 Replies
Login or Register to Ask a Question