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

Announcements

No record found.

News and Announcements icon
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 638

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
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    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

  • D365  beginner Profile Picture
    638 on at

    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.

  • D365  beginner Profile Picture
    638 on at

    Any help would be highly appreciated. 

  • Suggested answer
    MCallebert Profile Picture
    45 on at

    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));
    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 694

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 646 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 337

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans