web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get Accurate Age including leap year calculations?

(0) ShareShare
ReportReport
Posted on by 56

Hi,

I'm new CRM developer.I would like to calculate age based upon birthday and stored date in the system.

For Ex: DiffInDays(dateofbirth, referraldate) / 365 -But its not calculating leap year

            DiffinYears(dateofbirth, referraldate)  -not calculate accurate age with month and date

i will be appreciate for any help.

Thanks,

Piny

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at
    RE: How to get Accurate Age including leap year calculations?

    Hi Piny,

    If you want to get the age value without consideration of leap years, you can create an action similar to this:

    DiffInDays(dateofbirth, Now()) / 365

    If you need to handle leap years then you will need to create JavaScript instead.

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: How to get Accurate Age including leap year calculations?

    Hi Piny,

    please do refere following code:

    int age = ((DateTime.Now.Year - birthday.Year) * 372 + (DateTime.Now.Month - birthday.Month) * 31 + (DateTime.Now.Day - birthday.Day)) / 372;

    The above approach will solve your issue I hope.

    Thanks

  • Piny Profile Picture
    56 on at
    RE: How to get Accurate Age including leap year calculations?

    Thanks Adrian ,I am looking solution without using javascript.

  • Piny Profile Picture
    56 on at
    RE: How to get Accurate Age including leap year calculations?

    Formula is good but i can't use in CRM.

    If i used  Age=((DiffinYears(dateofbirth, now())*372) + (diffinmonths(dateofbirth, now())*31) + (diffindays(dateofbirth, now())))/372

    its calculation is different then arithmetic calculation and i cant use subtract month or year with date time field.

    Thanks for the solution Pravin

  • Verified answer
    Piny Profile Picture
    56 on at
    RE: How to get Accurate Age including leap year calculations?

    Hi,

    got solved today,so answer is

    TrimRight(Concat(((((DiffInYears(dateofbirth, anydate) * 372) + (DiffInMonths(AddYears(DiffInYears(dateofbirth, anydate), dateofbirth),anydate) * 31)) + DiffInDays(AddYears(DiffInYears(dateofbirth, anydate), dateofbirth), anydate)) / 372), ""), 11)

    Thanks

  • DevCrm16 Profile Picture
    215 on at
    RE: How to get Accurate Age including leap year calculations?

    in your solution formula what is the "anydate" reference?

  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at
    RE: How to get Accurate Age including leap year calculations?

    Hi Devon Toland,

    "anydate" is referring to a Date field.

  • wikky2007 Profile Picture
    40 on at
    RE: How to get Accurate Age including leap year calculations?

    Hi Piny,

    Thanks for the calculation, however, this formula only seems to work for leap years and odd-numbered years for dates before July 10th of that specified year (e.g., 7/10/1953 - this shows incorrectly as 64).  Any date in odd-numbered years between 7/10 and 12/31 shows incorrectly.

    Is there any way that you can update your formula to account for those dates as well? Thanks

  • Piny Profile Picture
    56 on at
    RE: How to get Accurate Age including leap year calculations?

    Hi try this formula :

    TrimRight(Concat(((((DiffInYears(dateofbirth, anydate) * 372) + (DiffInMonths(AddYears(DiffInYears(dateofbirth, anydate), dateofbirth), anydate) * 31)) + DiffInDays(AddMonths(DiffInMonths(dateofbirth, anydate), dateofbirth), anydate)) / 372), ""), 11)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans