Diff. between 2 dates in terms of years, months and days

manish_s_in
Member Posts: 4
Hi everyone,
is there any standard method in axapta, in which I pass two dates as argument(say me date of birth and current date) and it will return me the years, months and days in between them.
For ex. I entered my date of birth and current date, it will return me , how old I am , in terms of years, months and days.
Any idea is helpful...
Thanks
Manish
is there any standard method in axapta, in which I pass two dates as argument(say me date of birth and current date) and it will return me the years, months and days in between them.
For ex. I entered my date of birth and current date, it will return me , how old I am , in terms of years, months and days.
Any idea is helpful...
Thanks
Manish
Nothing is impossible
0
Comments
-
Here is a method you can add into your Global class:
static str myDateDiff(date _d1, date _d2, boolean _include = false)
{
date m_d1, m_d2; // m_d2 >= m_d1
str _s;
int m_year, m_mth, m_days;
;
if(_d1<_d2)
{
m_d1 = _d1;
m_d2 = _d2;
} else
{
m_d1 = _d2;
m_d2 = _d1;
}
m_year = yearDiff(m_d2,m_d1);
m_mth = mthOfYr(m_d2) - mthOfYr(m_d1);
if (m_mth < 0)
m_mth += 12;
m_days = dayOfMth(m_d2) - dayOfMth(m_d1);
if (m_days < 0)
{
m_mth--;
m_days += dayOfMth(dateEndMth(m_d1));
}
if (m_mth < 0)
m_mth += 12;
if (_include) m_days++;
if (m_days == dayOfMth(dateEndMth(m_d2)))
{
m_mth++;
m_days = 0;
}
_s = strltrim(strrtrim(strfmt("%1 year(s), %2 month(s), %3 day(s)", m_year, m_mth, m_days)));
return _s;
}
and here is an example of how to use it:
static void tutorial_DateDifference(Args _args)
{
date birthday = mkDate(27,01,1984);
date todayDate = SystemDateGet();
;
print myDateDiff(todayDate ,birthday);
pause;
}Vanya Kashperuk,
My blog - http://kashperuk.blogspot.com
MorphX IT in Russian - http://www.lulu.com/content/723888
Inside Dynamics AX 4.0 in Russian - http://www.ozon.ru/context/detail/id/37145820
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions