Announcements
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.
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)); }
Any help would be highly appreciated.
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.
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
André Arnaud de Cal...
294,233
Super User 2025 Season 1
Martin Dráb
232,982
Most Valuable Professional
nmaenpaa
101,158
Moderator