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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Year Question in Formula

Status
Not open for further replies.

Hashiba14

MIS
May 14, 2007
29
US
I am currently using Crystal 10 and I recieved a formula from this website that allows me to take a number field and convert it to a date field. Ex 91804 changes to 9/18/2004.

I'm having an additional problem when the years are before 2000, because the results are coming back as 9/18/2088.

This it the formula I got, but how can I fix it so that when the year is <2000, it will show as 1994.

Here is the formula.

stringvar MyDate := totext({badhdap.dadob},0,"");
if len(MyDate) = 5
then
cdate(2000+val(right(MyDate,2)), val(left(MyDate,1)),val(mid(MyDate,2,2)))
else
if len(MyDate) = 6
then
cdate(2000+val(right(MyDate,2)), val(left(MyDate,2)),val(mid(MyDate,3,2)))

 
Try:

stringvar MyDate := totext({badhdap.dadob},0,"");
if len(MyDate) = 5
then
(
if val(right(MyDate,2)) >= 50 then
cdate(1900+val(right(MyDate,2)), val(left(MyDate,1)),val(mid(MyDate,2,2))) else
cdate(2000+val(right(MyDate,2)), val(left(MyDate,1)),val(mid(MyDate,2,2)))
)
else
if len(MyDate) = 6 then
(
if val(right(MyDate,2)) >= 50 then
cdate(1900+val(right(MyDate,2)), val(left(MyDate,2)),val(mid(MyDate,3,2))) else
cdate(2000+val(right(MyDate,2)), val(left(MyDate,2)),val(mid(MyDate,3,2)))
)

I used 50 as the criterion for whether the date was 1900's or 2000's, but you can adjust as necessary.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top