How to calculate no. of month between two dates?

Aravindh_Navision
Member Posts: 258
Hi friends,
I need to calculate no. of months between two (From and End) dates. The From and End date can be first day and last day of the month respectively. Else From date can be mid of a month and End date can be mid of some other month. I want to count the no. of month in between the two dates. It should take care of no. of days in month also (i.e., 28, 30, 31).
Can anyone help to address this?
Thanks, Aarvi.
I need to calculate no. of months between two (From and End) dates. The From and End date can be first day and last day of the month respectively. Else From date can be mid of a month and End date can be mid of some other month. I want to count the no. of month in between the two dates. It should take care of no. of days in month also (i.e., 28, 30, 31).
Can anyone help to address this?
Thanks, Aarvi.
0
Comments
-
Providing that your start date is always the first day of a month. and the end date is alwasy the last day of a month, it may be something like this:
NoOfMonths := 1 + DATE2DMY(ToDate, 2) - DATE2DMY(FromDate, 2) + 12*(DATE2DMY(ToDate, 3) - DATE2DMY(FromDate, 3));
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Thank you Slawek_Guzek.
The solution you gave works well for the the period say 07/01/18 to 07/31/18 (mm/dd/yy). Suppose if the period starts and ends like 07/11/18 to 08/10/18 (dd/mm/yy) respectively, the difference between the two dates is 1 month. If I give start and end date as 07/11/18 to 08/10/18 (dd/mm/yy), I am getting the difference month as 2, which is wrong. How to calculate in this scenario?
Regards.0 -
How would you calculated this is in Excel or example?Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Hi Slawek_Guzek ,
Actually am doing this for calculating the warranty period of an Item.
For example: If I buy a product on 07/20/18. If the warranty for the product is 1 year then the warranty end date will be 07/19/19 (mm/dd/yy). Suppose if the warranty is for 1 month, then the end date will be 08/19/18 (mm/dd/yy).NoOfMonths := 1 + DATE2DMY(ToDate, 2) - DATE2DMY(FromDate, 2) + 12*(DATE2DMY(ToDate, 3) - DATE2DMY(FromDate, 3));
By using above formula, If I give start and end date as 07/11/18 to 08/10/18 (mm/dd/yy), I am getting the difference month as 2, which is wrong. I must get the value as 1 month. Also it should take care of last day of a month say 28, 29 for february month and 30, 31 for other months.
Thanks in advance.0 -
I get that.
I am asking if you tried to come up with a way of calculating this outside NAV? If you tried at all to solve the problem and what are your findings, so I can help you implementing them in NAV
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030
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