0

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 ?

Jonathan Lam
  • 1,237
  • 3
  • 20
  • 49

1 Answers1

1

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);
Hemisphera
  • 816
  • 6
  • 23
  • How can I convert integer (I will have the total of days as you proposed) to duration. Do you have an idea ? – Jonathan Lam Oct 30 '17 at 12:43
  • @lam simple answer- you can’t – Mak Sim Oct 31 '17 at 06:40
  • @Mak Sim you are wrong. You can. `Integer` and `Duration` are assignable to each other. I have updated my answer. – Hemisphera Oct 31 '17 at 08:03
  • @Hemisphera I know they are. Duration is basically an Integer. But it is not what was asked. @Lam wants to have duration between two points in time excluding weekends. So just multiplying days on milliseconds will not be an answer. You need something like `duration := datetime2 - datetime1 - DurationOfAllWeekends` – Mak Sim Oct 31 '17 at 08:58
  • Yes it is the answer, **if** the number of days I am multiplying already are the days without weekends. And in my case they are, because I am using the `Date` table to find the number of days, not counting weekends. Of course you can count only entire days this way. – Hemisphera Oct 31 '17 at 09:57