Search code examples
microsoft-dynamicsnavisiondynamics-navmicrosoft-dynamics-nav

How to remove weekdays in duration data type NAV


How can i remove weekdays in the data type duration in CAL ?

for example: duration := datetime2 - datetime1

But duration do contains Saturdays and Sundays. How can i remove them ?


Solution

  • Simple answer: you can not.

    But you can use the Date virtual table. Something like this:

    Date.SETRANGE("Period Type", Date."Period Type"::Date);
    Date.SETFILTER("Period Start", '%1..%2', DT2DATE(datetime1), DT2DATE(datetime2));
    Date.SETRANGE("Period No.", 1, 5); // only days 1 - 5 = weekdays
    EXIT(Date.COUNT); // returns number of days
    

    You can then convert the number of days to a duration with a simple multiplication. A Duration is nothing more than the number of milliseconds.

    1 hour = 3600000ms.

    Therefore:

    MESSAGE('%1', NoOfDays);
    dur := NoOfDays * 24 * 3600 * 1000;
    MESSAGE('%1', dur);