Solved

Informix SQL get age from ddmmyyyy field

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

809 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