Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting DOB field to years & months with a caveat 1

Status
Not open for further replies.

erniewyles

Technical User
Oct 5, 2009
3
US
Ok, so here's what I am trying to do.
Firstly, I want to convert the person's current age to years and month, i.e. if the person is now 25 years and 3 months old, it is listed as 25.3.

But here's the twist, if the months are a particular number, they have to be changed according to the following table:

(Using the above example of 25 years and X months in 25.X format)
if month value is 0 then it is 0, i.e. 25.0 would remain 25.0
if month value is 1 then it is 1, i.e. 25.1 would remain 25.1
if month value is 2 then it is 2, i.e. 25.2 would remain 25.2
if month value is 3 then it is 3, i.e. 25.3 would remain 25.3
if month value is 4 then it is 3, i.e. 25.4 would be 25.3
if month value is 5 then it is 4, i.e. 25.5 would be 25.4
if month value is 6 then it is 5, i.e. 25.6 would be 25.5
if month value is 7 then it is 6, i.e. 25.7 would be 25.6
if month value is 8 then it is 7, i.e. 25.8 would be 25.7
if month value is 9 then it is 8, i.e. 25.9 would be 25.8
if month value is 10 then it is 8, i.e. 25.10 would be 25.8
if month value is 11 then it is 9, i.e. 25.11 would be 25.9
 
//if the person was 305 months old
//they would be
round(int(305/12)+round(remainder(305,12)/12,1),1)

or 25.4 years old

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
Well, although I do appreciate your response, I think you may have misunderstood.

The original output is a basic DOB: 04/25/1984

That date would need to first be converted to years and month. Using my example of 04/25/1984 would yield the value 25.5 which equates to 25 years and 5 months.

With the 25.5 value in place I then need to refer to the above conversion while looking at the month number of my value. If the month is .5 then it needs to change to .4, thus my final number in my example would be 25.4
 
Maybe I read things wrong but I dont think so....

04/25/1984 would yield the value 25.5 (306/12) but its not equal to 25 years and 5 months.. its actually 25 years and 6 months... which should be 25.5 based on your conversion chart.


your conversion chart is not as difficult as I tried to make it all day. if you divide 1 through 12 (months) by 12 and round that to tenths, you will see the same results your chart shows.

If thats not what you understand of your requirements then I cant help....

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
1 divided by 12 rounded = .1
2 divided by 12 rounded = .2
3 divided by 12 rounded = .3
4 divided by 12 rounded = .3
5 divided by 12 rounded = .4
6 divided by 12 rounded = .5
7 divided by 12 rounded = .6
8 divided by 12 rounded = .7
9 divided by 12 rounded = .8
10 divided by 12 rounded = .8
11 divided by 12 rounded = .9
12 divided by 12 rounded = .0


_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
aaah....interesting. Sorry i didn't notice that you indeed were correct.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top