Skip to main content

How To Calculate Difference Between Two Dates in Navision 2013 R2 and Higher ?

Hi All,

It was always been a trouble to calculate Difference Between Two Date Time Variables.

With Microsoft Dynamics NAV 2013 R2, Dotnet Variable are available which make life easy in so many situations. Today we will discuss one of the Dotnet Component for calculation Difference between days.

This Solution can be implemented on Navision Version  2013 R2 and Later. The Demo Steps are on NAV 2016 W1 Database.



1. Let's Create a Page Date Demo, with Two Input Variables of StartDateTime & EndDateTime of Type DateTime.

2. The Page Should Look Like as below.



3. I am Creating three Dotnet Variables as below -

DateandTime  - Microsoft.VisualBasic.DateAndTime.'Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

DayOfWeekInput - Microsoft.VisualBasic.FirstDayOfWeek.'Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

WeekOfYearInput - Microsoft.VisualBasic.FirstWeekOfYear.'Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

4. Actually The First Variable Does the Magic what we want. So let's understand the use of Other Two.

DayOfWeekInput argument can have one of the following settings  - 
 0 - First day of week specified in system settings
 1 - Sunday (default)
 2 - Monday (complies with ISO standard 8601, section 3.17)
 3 - Tuesday
 4 - Wednesday
 5 - Thursday
 6 - Friday
 7 - Saturday

WeekOfYearInput argument can have one of the following settings - 
 0 - First week of year specified in system settings
 1 - Week in which January 1 occurs (default)
 2 - Week that has at least four days in the new year (complies with ISO standard 8601, section 3.17)
 3 - First full week in the new year

** I will be Using Default for both the parameters in the demo. 

You can change it based on your need.For Changing These You can just call the Enumerators as per your need from the C/AL Symbol Menu as shown Below.


5. Now let's see how our DateandTime , dotnet variable fullfill the requirement which we are looking for.

- If you Check the Functions that this variable have in C/AL Symbol Menu, you will find a function DateDiff, Which will return the Difference between two date time variables, as below -


6. Now we know all marked as Green in our Above Image, but still the first parameter which is red is mystery.

The First Parameter i.e Date Interval, will decide what you want in Result. You Might ways difference, in months, days, Quarter, Year, Minutes, Seconds, Hours... and many more..

The Dotnet Class Give You 10 Options In which You can Get the Object. Below is the list of Options that you have -

- Day              
- Day Of Year
- Hour            
- Minute
- Month          
- Quarter
- Second
- Week
- Calendar week
- Year

7. For the Demo, I will be creating 10 integer type variables for showing output in all result types, as below - 
** Add all these variables in a Seprate Group in Page.


 8. I Will Create a Function To Set and Reset these Variables which will be called on Validate of My Two Input date Variables as shown below -


9. Let's Run the Page and See output of difference between two date time variables.


References - MSDN

Hope You find the demo useful. You can use any of the command in the above list as per your requirement in the C/AL code.

If required You can download the Date Demo Objects from Dynamics User Group OR my Skydrive.

File Name - Microsoft Dynamics NAV 2016 - Saurav-NAV.19.00.DateDemo

Regards,
+saurav dhyani
saurav-nav.blogspot.com

Comments

Popular posts from this blog

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

RTC Report It is not possible to instantiate the Visual Studio bridge.

Hi all, As a Navision developers I have Multiple Versions of Navision running in single Machine. As discussed Earlier in the post how to run multiple Version of RTC in single machine. So my machine have following details for RTC Versions - NAV 2009 R2    - is installed. NAV 2009 SP1  - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 SP1 IN\ NAV 2009         - is copied at C:\Program Files (x86)\Microsoft Dynamics NAV\60\NAV 6.0 IN\ This approach has been working great for execution of Classic and RTC Clients. However, after installing Dynamics NAV 2009 R2, if i tried to view the Layout for an NAV 2009 SP1 Report i was getting the following error: ---------------------------  Microsoft Dynamics NAV Classic  ---------------------------  It is not possible to instantiate  the Visual Studio bridge.  ---------------------------  OK    --------------------------- After searchi...

NAV 2013 R2 - Cumulative update 12 Released.

Hi all, Please find below the details of  Cumulative Update 12 released for Microsoft Dynamics NAV 2013 R2. Title - Cumulative Update 12 for Microsoft Dynamics NAV 2013 R2 Build No. - 38053 Release Date - October, 2014 Local Version Included - AU, AT, BE, CH, DE, DK, ES, FI, FR, IS, IT, NA, NL, NO, NZ, SE, UK, RU Download Link Note: Implementing this cumulative update will require a database conversion unless you have already implemented update rollup 5.