?
Solved

Informix SQL get age from ddmmyyyy field

Posted on 2011-02-22
4
Medium Priority
?
2,186 Views
Last Modified: 2012-05-11
The code below is not accurate as it only minuses the year

year(today)-year(DOB) as AGE

does anybody know a more accurate way of returing a persons age taking into account the day and month of the year as well?


0
Comment
Question by:JCTDD
[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
  • 2
4 Comments
 
LVL 7

Expert Comment

by:jhp333
ID: 34956558
1. Simple, but approximate solution:
select ((today - DOB) / 365.25)::int

2. Accurate one:
select year(today) - year(DOB) - case when mdy(month(DOB),day(DOB),year(today)) > today then 1 else 0 end
0
 

Author Comment

by:JCTDD
ID: 35014658
running 2. Accurate one: in aqua studio I get error:

"Invalid day in date"

select year(today) - year(mailing_code) - case when mdy(month(mailing_code),day(mailing_code),year(today)) > today then 1 else 0 end
from table_1

Open in new window


do you know what is wrong?
0
 

Author Comment

by:JCTDD
ID: 35014663
example DOBs from the mailing_code field:
mailing_code
26/03/1941
1/10/1958
21/07/1961
0
 
LVL 7

Accepted Solution

by:
jhp333 earned 2000 total points
ID: 35014860
You need to set an environment variable, DBDATE.
It seems your date format requires DBDATE="DMY4/"
Actual syntax for setting environment variable depends on the OS.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
In this article, we’ll look at how to deploy ProxySQL.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
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…

741 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