Try this
DATETIMEVAR StDate:= Startdatetime
DATETIMEVAR EndDate:= enddatetime;
NUMBERVAR Weeks;
NUMBERVAR Days;
TIMEVAR SLA_Open := TIME(8,0,0);
TIMEVAR SLA_Close := TIME(17,00,0);
NumberVar WeekendTime ;
NUMBERVAR NonWorkTime ;
NUMBERVAR Weeks;
NUMBERVAR Days;
IF WeekDayName(DAYOFWEEK(StDate)) = "Saturday" THEN
StDate:= DATETIMEVALUE(DATE(DATEADD('D',2,StDate)) , SLA_Open);
IF WeekDayName(DAYOFWEEK(StDate)) = "Sunday" THEN
StDate:= DATETIMEVALUE(DATE(DATEADD('D',1,StDate)) , SLA_Open);
IF TIME(StDate) > SLA_Close THEN
StDate := DATETIMEVALUE(DATE(StDate) , SLA_Close);
IF TIME(StDate) < SLA_Open THEN
StDate := DATETIMEVALUE(DATE(StDate) , SLA_Open);
IF WeekDayName(DAYOFWEEK(endDate)) = "Saturday" THEN
endDate = DATETIMEVALUE(DATE(DATEADD('D',2,endDate)) , SLA_Open);
IF WeekDayName(DAYOFWEEK(endDate)) = "Sunday" THEN
endDate = DATETIMEVALUE(DATE(DATEADD('D',1,endDate)) , SLA_Open);
IF TIME(endDate) > SLA_Close THEN
endDate := DATETIMEVALUE(DATE(endDate) , SLA_Close);
IF TIME(endDate) < SLA_Open THEN
endDate := DATETIMEVALUE(DATE(endDate) , SLA_Open);
Weeks:= (Truncate (EndDate - dayofWeek(EndDate) + 1 - (StDate - dayofWeek(StDate) + 1)) /7 ) * 5;
Days := DayOfWeek(EndDate) - DayOfWeek(StDate) + (if DayOfWeek(StDate) = 1 then -1 else 0) +
(if DayOfWeek(EndDate) = 7 then -1 else 0);
// Non Worktime on Business days
NonWorkTime := DATEDIFF("N",DATETIMEVALUE(CurrentDate, SLA_Close),DATETIMEVALUE(CurrentDate+1,SLA_Open)) * (Weeks + Days);
//a weekend in minutes is Count of saturdays and sundays * 24 hours * 60 minutes
WeekendTime := (DateDiff("ww",stDate,Enddate, crSaturday ) +DateDiff("ww",stDate,Enddate, crSunday)) * 24 * 60;
(DATEDIFF('N', stDATE, endDate)- NonWorkTime - WeekendTime )/60
Jyothi
|