Solved

Informix SQL get age from ddmmyyyy field

Posted on 2011-02-22
4
2,133 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 500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 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