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 :
Finance | Project Operations, Human Resources, ...
Suggested answer

Display Age in Years - Months - days

(0) ShareShare
ReportReport
Posted on by 618

Hi Experts,

I have a custom asset table where I have acquisition date for each asset. I need to display the age of assets in Year- month - days format (Example:- 1 Year 2 months 5 days) in the form, What is the best way to get this done. Instead of a display field if user can sort the records by age that would be great. Any suggestions please. 

Currently the age is being displayed in the form in months using the below. 

Display int NoOfMonths()
{
if(this.DateAcquisition)
{
return intvNo(today(),this.DateAcquisition,IntvScale::YearMonth);

}
else
{
return 0;
}
}

Thanks in advance. 

I have the same question (0)
  • Suggested answer
    MCallebert Profile Picture
    45 on at
    RE: Display Age in Years - Months - days

    Hi,

    you can try something like this :

    static void Job149(Args _args)
    {
        int             years, months, days;
        utcDateTime     yourUtcDateTime;  
        date            yourDate;
        
        yourDate = mkDate(17,11,2020);
       
        months = mthOfYr(systemdateget()) - mthOfYr(yourDate);
        years = year(systemdateget()) - year(yourDate);
        
        if (dayOfMth(systemdateget()) < dayOfMth(yourDate))
        {
             months--;
        }
        
        if (months < 0)
        {
            years--;
            months  = 12;
        }
        
        #timeConstants
        yourUtcDateTime = DateTimeUtil::addMonths(DateTimeUtil::newDateTime(yourDate,0), ((years * 12)   months));
        days = DateTimeUtil::getDifference(DateTimeUtil::newDateTime(systemdateget(),0) , yourUtcDateTime) / #secondsPerDay;
        info(strFmt("%1 years %2 months %3 days", years, months, days));
    }

  • D365  beginner Profile Picture
    618 on at
    RE: Display Age in Years - Months - days

    Any help would be highly appreciated. 

  • D365  beginner Profile Picture
    618 on at
    RE: Display Age in Years - Months - days

    Thanks Mr. Ludwig for the response.

    Yes, The management just need to see the asset age in Years and Months in the form. No need of days actually, but for the sake of curiosity I was asking if it is possible to do or not.

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Display Age in Years - Months - days

    Hi AX beginner,

    What's the use case for this requirement?

    Is it just that management wants to know how old an asset is?

    If so, why do you need the days?

    I would assume that the year and month should be sufficient.

    Would be great if you could elaborate.

    Many thanks,

    Ludwig

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,239

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 767 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 672 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans