Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

How to Caclutae Age in Years, Moths and Days

(0) ShareShare
ReportReport
Posted on by 25

HI,

Bit new to CRM Could you kindly Advice how to Calculate Age in below format(in Years, Moths and Days). I Could not find any Info on this in any forums.

pastedimage1650183108185v1.png

Regards

Ja

  • Suggested answer
    jagathsb Profile Picture
    jagathsb 70 on at
    RE: How to Caclutae Age in Years, Moths and Days

    Thank you for this Asmaa

  • jagathsb78 Profile Picture
    jagathsb78 25 on at
    RE: How to Caclutae Age in Years, Moths and Days

    Thanks

  • Suggested answer
    Asmaa Bouhmidi Profile Picture
    Asmaa Bouhmidi 135 on at
    RE: How to Caclutae Age in Years, Moths and Days

    Hello Jag, i tried to make it clearer

    6330.2022_2D00_04_2D00_18_5F00_03h09_5F00_26.png5226.2022_2D00_04_2D00_18_5F00_03h10_5F00_01.png

  • jagathsb78 Profile Picture
    jagathsb78 25 on at
    RE: How to Caclutae Age in Years, Moths and Days

    HI Asmaa,

    Thank you I did download and tried importing and getting below error

    pastedimage1650354951993v1.png

    the below expressions you mentioned where do they go.

    1. sub(int(formatDateTime(utcNow(), 'yyyy')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'yyyy'))) //to    abstract today year and Bod year

    2. sub(int(formatDateTime(utcNow(), 'mm')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'MM'))) //to abstract    today month and Bod month

    3. sub(int(formatDateTime(utcNow(), 'dd')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'dd'))) //to abstract    today day and Bod day

    4. add(12,sub(int(formatDateTime(utcNow(), 'mm')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'mm'))))  

    5. add(31,sub(int(formatDateTime(utcNow(), 'dd')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'dd'))))

    at the end add an update row to update the Age field

    Thanks

    Jag

  • Suggested answer
    Asmaa Bouhmidi Profile Picture
    Asmaa Bouhmidi 135 on at
    RE: How to Caclutae Age in Years, Moths and Days

    i exported solution and put it in this link, try to install it in you environment 

    https://we.tl/t-OSBKsgj8Ki

  • Suggested answer
    Asmaa Bouhmidi Profile Picture
    Asmaa Bouhmidi 135 on at
    RE: How to Caclutae Age in Years, Moths and Days

    Hello,

    I do have with me but i'm not sure how can i share it with you i tried to describe the way i did it and add the expressions and algorithm to achieve this

  • jagathsb78 Profile Picture
    jagathsb78 25 on at
    RE: How to Caclutae Age in Years, Moths and Days

    Hi Asmaa,

    Thank you for the Reply, this is amazing, if you dont mind me asking do you have a solution for this.

    Thanks

    Jag

  • Suggested answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: How to Caclutae Age in Years, Moths and Days

    Hi Ja,

    You can create a custom field whose type is a calculated field to calculate the age.

    1.Make your DOB field behavior is not date only, otherwise, you can’t use Diffyear function with Now() and birdthdate.

    Image

    2.For original age field, you can’t change its field type, so you need new another age field (field type is calculated).

    Image

    3.When all is set and publish all, you can refresh page, then calculated field will show correct age directly.

    Also, you can use Flow to update age, which don’t need create another field.

    1.Go Power Apps(https://make.powerapps.com/ ) to create an instant flow.

    Image

    2.Add ‘condition’ step.

    Image

    3.In Yes branch:

    (1) Add ‘compose’ step.

    Image

    (2) Add ‘Update a record’ step.

    Image

    split(string(div(div(sub(ticks(utcNow()),ticks(outputs('Compose'))),864000000000),365.25)),'.')[0]

    4.Save and test.

    In the view, select records you need and expand flow to click the flow just created.

    Then wait for several minutes and refresh page, the age will be changed.

    Image

  • Suggested answer
    Asmaa Bouhmidi Profile Picture
    Asmaa Bouhmidi 135 on at
    RE: How to Caclutae Age in Years, Moths and Days

    Hello,

    Since you are trying to calculate the age, then this action will be done daily, then i command you to use a Schedule Flow,

    I have created a text field and called it Diff Date where i will store the age as you described,

    then i have created a flow as follow : 

    2022_2D00_04_2D00_18_5F00_03h02_5F00_42.png

    First initialize you variable 

    Age Year, Age Month and Age Day stays empty until we fill them later on

    Now Year = int(formatDateTime(utcNow(), 'yyyy'))

    Now Month = int(formatDateTime(utcNow(), 'mm'))

    Now Day = int(formatDateTime(utcNow(), 'dd'))

    add a list row action and apply the following algorithm

     if (monthNow >= monthDob)
        var monthAge = monthNow - monthDob;
      else {
        yearAge--;
        var monthAge = 12 + monthNow -monthDob;
      }
    
      if (dateNow >= dateDob)
        var dateAge = dateNow - dateDob;
      else {
        monthAge--;
        var dateAge = 31 + dateNow - dateDob;
    
        if (monthAge < 0) {
          monthAge = 11;
          yearAge--;
        }
      }

    4278.2022_2D00_04_2D00_18_5F00_03h09_5F00_26.png1817.2022_2D00_04_2D00_18_5F00_03h10_5F00_01.png

    those are the following expressions used in this flow:

    sub(int(formatDateTime(utcNow(), 'yyyy')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'yyyy'))) //to abstract today year and Bod year
    sub(int(formatDateTime(utcNow(), 'mm')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'MM'))) //to abstract today month and Bod month
    sub(int(formatDateTime(utcNow(), 'dd')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'dd'))) //to abstract today day and Bod day
    add(12,sub(int(formatDateTime(utcNow(), 'mm')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'mm')))) 
    add(31,sub(int(formatDateTime(utcNow(), 'dd')), int(formatDateTime(items('Apply_to_each')?['birthdate'], 'dd'))))
    at the end add an update row to update the Age field 
    2022_2D00_04_2D00_18_5F00_03h15_5F00_52.png
    2022_2D00_04_2D00_18_5F00_03h10_5F00_35.png
    and this should work perfectly
    2022_2D00_04_2D00_18_5F00_03h16_5F00_35.png
    Please mark my answer as resolved if you find this helpful 

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,703 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,433 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans