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

Simple Convert Date and Datediff formula 2

Status
Not open for further replies.

Chuck712

Technical User
Mar 1, 2002
133
US
Being new to Crystal, I have a field that is formatted as a string, but is a date field. I need to create a formula that calculates an age from this date. Here is what I have.

If not(isnull({tablename;1.Birthday}))then
DateDiff ('yyyy',Today() ,CDate({tablename;1.Birthday}))
ELSE
00000000
What is happening is that when the string or date is blank, then I get an error when previewing the report.
What I want is just a blank field.
I have searched the previous posts, but can't seem to get this to work.
 
Try:

If not(isnull({tablename;1.Birthday}))
and
isdate({tablename;1.Birthday})
then
DateDiff ('yyyy',Today() ,CDate({tablename;1.Birthday}))
ELSE
0

Posting that you get an error but not including what the error message is doesn't help, you'll just get questions.

You also state that you want a blank of nothing is returned, so you'll want to format the formula to suppress if the value is zero, or change the default of zero to nothing.

-k
 
Thank you so much. This was it. I am not the best "coder" in the pile. I will remember the tip for including the error message. I access this through a very secure remote desktop application and sometimes the error is gone when I try to retrieve it. Thanks again.
 
Your formula will not give an accurate age, as the year difference does not take into account the month and day, i.e., datediff('yyyy',date(2005,12,31),date(2006,1,1)) would return a 1 year difference even though it is really only one day. You might want to check out Ken Hamady's age formula in faq767-995.

-LB
 
Thank you. This was more than helpful and works great. It would have been easier with an actual date formatted field, but this is much more accurate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top