Home
Crystal Reports Training
Crystal Reports XI
Crystal Reports .NET
Crystal Reports Forum
News
Tech Support
Active Topics
Memberlist
Search
Help
Register
Login
Technical Questions
Crystal Reports Forum
:
Crystal Reports 9 through 2022
:
Technical Questions
Topic: formula to calculate age
Author
Message
sanchezgmc06
Senior Member
Joined: 21 Jan 2011
Online Status: Offline
Posts: 107
Topic: formula to calculate age
Posted: 27 Apr 2012 at 12:01pm
Hi i need a formula to calculate the clients age. I have the date of birth field
thanks
IP Logged
yggdrasil
Senior Member
Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Posted: 30 Apr 2012 at 3:31am
numbervar dys;
numbervar yrs;
days :=DateDiff ('d', date_of_birth,currentdate );
yrs := int(dys/365);
dys := dys - yrs * 365;
Age will be 'yrs' years and 'dys' days.
If you want age as decimal years just use yrs := dys/365
IP Logged
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Posted: 30 Apr 2012 at 3:59am
another approach is to use the datediff and datepart together to avoid leap year issues...
datediff('yyyy',{table.DOB},currentdate)-(if datepart('y',currentdate)>datepart('y',{table.DOB}) then 0 else 1)
Edited by DBlank - 30 Apr 2012 at 3:59am
IP Logged
aaml216
Newbie
Joined: 02 Nov 2011
Online Status: Offline
Posts: 24
Posted: 30 Apr 2012 at 6:37am
DBlank - this is so helpful - I copied and pasted it right into my formula editor (changing table.field). How do I get age in months? (babies)
Amanda from the Mid-Atlantic
IP Logged
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Posted: 30 Apr 2012 at 6:51am
how are you defining months exactly?
IP Logged
kostya1122
Senior Member
Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Posted: 30 Apr 2012 at 6:59am
this could work if the kids are under 1
(currentdate - {MEMB_COMPANY_V.BIRTH})/365*12
IP Logged
aaml216
Newbie
Joined: 02 Nov 2011
Online Status: Offline
Posts: 24
Posted: 30 Apr 2012 at 7:02am
kostya - I'll give that a try. It looks like how I write formulas in Excel.
DBlank - I am only looking at kids under 2 so I want to see:
--3 months old rather than 0 years old
--19 months old rather than 1 year old
Amanda from the Mid-Atlantic
IP Logged
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Posted: 30 Apr 2012 at 7:09am
this does not look to see the days of the month but it would be sometning like this
if
//months
(datediff('yyyy',{@dob},currentdate)-(if datepart('y',currentdate)>datepart('y',{@dob}) then 0 else 1))<2 then
totext(datediff('m',{@dob},currentdate),0,'') & ' months'
else
//years
totext((datediff('yyyy',{@dob},currentdate)-(if datepart('y',currentdate)>datepart('y',{@dob}) then 0 else 1)),0,'') & ' years'
IP Logged
sanchezgmc06
Senior Member
Joined: 21 Jan 2011
Online Status: Offline
Posts: 107
Posted: 30 Apr 2012 at 8:09am
perfect! thanks
IP Logged
dbodell
Groupie
Joined: 08 Nov 2011
Location: United States
Online Status: Offline
Posts: 53
Posted: 30 Apr 2012 at 9:59am
It's actually more accurate if you divide by 365.25 due to leap years.
Thanks,
D. Bodell
IP Logged
Printable version
Forum Jump
-- Select Forum --
Announcements
Talk with the Author
Self-Publishing
Job Postings
New feature request
Report Design
Data Connectivity
Technical Questions
Tips and Tricks
Crystal Xcelsius
Report Design
Data Connectivity
Writing Code
Tips and Tricks
Report Design
Data Connectivity
Writing Code
Tips and Tricks
You
cannot
post new topics in this forum
You
cannot
reply to topics in this forum
You
cannot
delete your posts in this forum
You
cannot
edit your posts in this forum
You
cannot
create polls in this forum
You
cannot
vote in polls in this forum
HOME
|
FREE EBOOK
|
PROGRAMMING GUIDE
|
PURCHASE
|
REVIEWS
|
CONTACT ME
|
FAQ
|
LINKS
|
PRIVACY
|
CLICK PLAYS
|
BAEZL
© 2004-2026 Brian Bischof. All Rights Reserved.