Monday, February 28, 2011

Crystal Reports : Calculating Age

One of the many things you will want to do with a bona-fide date field is calculate age.Crystal makes it easy for us here; as long as we're comparing two date type fields, we can perform simple math.Let us suppose that the date field in question is {CONTACTS.SOURCEDATE}, which represents when a particular prospect was imported into our database.

1. We can see how many records were imported in the last seven days

{CONTACTS.SOURCEDATE} <= CurrentDate() - 7

2. Or how "old" any particular record is, expressed in days

CurrentDate() - {CONTACTS.SOURCEDATE}

3. To calculate the age in years, we must use the Crystal DateDiff function:

DateDiff("yyyy", {CONTACTS.SOURCEDATE}, CurrentDate())

The "yyyy" specifies we want the answer in years; "m" and "d" are also options (months and days, correspondingly)

1 comment:

BlogCatalog

Welcome To The Marks Group Blog

Welcome to our friends and clients. Here you'll find all of our prior GoldMine, Microsoft CRM, Quickbooks, HEAT and Crystal newsletter tips as well as links to my columns in Forbes and Businessweek and other announcements.

Please visit our website at www.marksgroup.net for free whitepapers, training info and more information on ways to do things quicker and better.