week days

Hello, Can someone help me to find out how to calculate the numbers of “working days” (or week days)between 2 dates. How can I use CALCDATE to do that Thanks

Hi, 1. DaysDifference := - 2. If you want to exlude all sundays and saturdays, i would count up from starting date in a loop and check with date table if current date is weekend or not. If it is weekend day don’t count this day otherwise count it.

Ok, but I was wondering if there was some existing function to count this like WD CW and so on. Thanks anyway

CALCDATE calculates date by date formula, and can’t calculate no of days. For that you can use virtual table Date, filter “Period type” = Date, “Period no” < 6, “Period start” - as you want, and then count all entries.

A great source of information in your case could be codeunit 7600 Calendar Management. There you can find all kind of functions to calculate dates, considering the clenders in Navision. Francis

Pretty simple [;)], create a record of type Date. = MyDate with Mydate do begin setcurrentkey("period type","period start"); setrange("period type","period type"::Date); setrange("Period Start",MyStartDate,MyEndDate); Setrange("Period No.",1,5); NoOfWorkDays := Count; end; PS I typed this from memory, and have never tried it, but it should work. Since Date is a virtual table, performance should be OK.

David, I just tried your code on Your database And it works fine Thank You [:D][:D][:D]

Great, glad to help.

create a record of type Date. = MyDate with Mydate do begin… Not possible with a type date? MyDate record of …? More info required please Gr. Markus

I might be wrong, but won’t Davids code include public holidays which aren’t working days? Alex.

There’s an existing function in the Calendar Management codeunit called CalcDateBOC that uses the Base Calendar specified. This function will accept any date formula, calculates the raw number of days (let’s call this x) in the formula and then calculates an end date based on x number of workdays. This function will exclude all dates in the specified base calendar that are marked as nonworking.

Another possibility is to checkout a file I use for my Delphi development called esbdates. In it there are many, many date functions and the conversion from Delphi to C/AL is easy. Django