Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to simply get age with calculated field

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello,

I'm very disappointing by Dynamics, some simple thing is not possible without complicated workaround for example I just want get contact Age from calculated field on this entity.

Unfortunately I'm unable use Diffyear with Now() and birdthdate :

DIFFINYEARS(birthdate,NOW()) -> not compatible fields

But

DIFFINYEARS(birthdate,birthdate) -> compatible

DIFFINYEARS(NOW(),NOW()) -> compatible


That very strange isn't it ?

Is there a simple way to do that ?

Thanks,

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to simply get age with calculated field

    If you choose the DIFFINYEARS approach you need in total four custom fields:

    custom field birthday_custom (Date and Time) with business rule to write the value of oob field birthday into the custom field --> is needed because you cannot use date functions on the oob field

    calculated field today with formula Now() --> is needed because you cannot use functions in conditions if using calculated values

    calculated field next_birthday with formula AddMonths(DiffInYears(birthday_custom, Now()) * 12, birthday_custom)

    calculated field field age with formulas:

    if next_birthday greater than today

    DiffInYears(new_geburtstagcustom, new_nextbirthday) - 1

    else

    DiffInYears(new_geburtstagcustom, new_nextbirthday) 

  • RugerSR762 Profile Picture
    RugerSR762 375 on at
    RE: How to simply get age with calculated field

    Any ideas as to why the DIFFINYEARS function only looks at the year but not the actual date?  For instance we enter DOB 7/1/2000 and it should return 19 as that is the current age.  However, it is returning 20.  The same holds true for any date entered (also ran it all they way up through 12/31/2000 and getting 20 as the calculated result). Is there a different, non code solution or would JS be a better approach?

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to simply get age with calculated field

    Birthdate being the system field, it is not available to change the behaviour/format so you have to create  new field with the datetime behaviour in order to use the calculated field functionality. If you still want to use out of box birthday field then you can create a business rule (entity level) to copy the birthday value to your custom dDOB field and then hide that field.

    This way, user will set the birthdate on birthday field, which will be copied to custom DOB field and the then the age is calculated from your custom DOB field.

    birthday.png

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to simply get age with calculated field

    Thank for your reply,

    But realy I must create a custom field to calculate that ? That's ridiculous.....

    Even is easier in excel to calcultate it

    Is there not a possibility to caste birthdate field ?

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to simply get age with calculated field

    Hi,

    This is because NOW() is a date time so you have to make your DOB field format as Datetime in that case instead if date only format. I understand its look odd DOB with time , you can set time with 00 using JS .  Here I did  have a look below screenshot -

    2019_2D00_05_2D00_01_5F00_1_2D00_05_2D00_55.png

    2019_2D00_05_2D00_01_5F00_1_2D00_05_2D00_55.png

    Here is the result -

    2019_2D00_05_2D00_01_5F00_1_2D00_07_2D00_09.png

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans