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

Age formula with weeks and days

Status
Not open for further replies.

risman

IS-IT--Management
Mar 13, 2002
29
US
Hello,
I am using age formulas in a report which work very well. How can I add on to the formulas below to specify years, monthes, weeks, and days old? Ex.: Little Bobby is 7 years, 8 months, 3 weeks, 2 days old today!
Thanks!
Risman

If Month({table.dob}) <= Month(CurrentDate)
and
Day({table.dob}) <= Day(CurrentDate)) then
Year(CurrentDate) - Year({table.dob})
else
Year(CurrentDate) - Year({table.dob})) – 1



WhileReadingRecords;
DateVar Birth:= {DOBField};
DateVar Ann:=CurrentDate;

if (Month(Ann) * 100) + Day (Ann) >=(Month(Birth) *100) + Day (Birth)
then Year (Ann) - Year(Birth)
else Year (Ann) - Year(Birth) -1
 
Your year formula looks fine:

if Month({TABLE.DOB}) <= Month(CurrentDate) and
Day({TABLE.DOB}) <= Day(CurrentDate)) then
Year(CurrentDate) - Year({TABLE.DOB})
else
(Year(CurrentDate) - Year({TABLE.DOB})
) – 1

months:
if month(CurrentDate)-month(TABLE.DOB) > 0 then
month(CurrentDate)-month(TABLE.DOB)
else
0

weeks:
if day(CurrentDate)-day(TABLE.DOB) > 6 then
truncate( (day(CurrentDate)-day(TABLE.DOB))/7 )
else
0

days:
if day(CurrentDate)-day(TABLE.DOB) > 0 then
remainder((day(CurrentDate)-day(TABLE.DOB))/7)
else
0

-k
 
Don't I have to use &quot;Remainder&quot; somehow after the first part calculates the years, then again after months and then again after weeks?
Thanks-
 
There is a datetimediff UFL download available at crystal decisions that returns U years, V months, W days, X hours, Y minutes, Z seconds, if this is what you are looking for.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top