Number of days between two dates excluding weekends
Here’s the code that can be used within a custom function to find the number of days between two dates excluding weekends.
It uses Data Services’s built-in-function day_in_week().
$l_Start and $l_End are the two input dates ; $l_last_weekday_7 and $l_last_weekday_6 are of type DATE ; $l_workdays is INT
$l_last_weekday_7 = $l_start + ((7 - day_in_week($l_start))%7);
$l_last_weekday_6 = $l_end + ((-1 * (day_in_week($l_end) + 1))%7);
$l_workdays= ((($l_last_weekday_6 - $l_last_weekday_7) + 1) / 7) * 5;
$l_workdays= decode ( ($l_last_weekday_7 <> $l_start) , $l_workdays+ (6 - day_in_week($l_start)),0);
$l_workdays = decode ( ($l_last_weekday_6 <> $l_end ) and (day_in_week($l_end) <6) , $l_workdays+ day_in_week($l_end) , $l_workdays);
print ($l_workdays);
Hello Magesh, I tried this code but didn't work for me. I might be wrong, but these are the values 2016-01-02/2016-01-09 that I took for the $L_Start and L_End variables and the Output value I got is 3, which should be 5.
Regards,
Pradeep.
Pradeep Rama , I have modified the code, have a look.