Posted By

elightbo on 03/23/07


Tagged


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

jeffld
jimmayes
ckayra
bradless
asifrizvigmailcom


calculate business days ( excluding holidays )


 / Published in: ASP
 

URL: http://groups.google.com/group/microsoft.public.inetserver.asp.general/browse_thread/thread/dde8757efac1fee/9a323acecf7e4372?lnk=st&q=calculate+weekdays+group%3A*.asp&rnum=3#9a323acecf7e4372

  1. datefrom = date
  2. dateto = date - 100
  3.  
  4. Response.write "Business Days: " & BusinessDateDiff(datefrom,dateto)
  5.  
  6. Public Function BusinessDateDiff( Date1 , Date2 )
  7.  
  8. Dim iWeekday1
  9. Dim iWeekday2
  10. Dim lDateDiff
  11. Dim lWeeks
  12. Dim dTemp
  13.  
  14. If Date1 > Date2 Then
  15. dTemp = Date1
  16. Date1 = Date2
  17. Date2 = dTemp
  18. End If
  19.  
  20. iWeekday1 = WeekDay(Date1, vbMonday) - 1
  21. iWeekday2 = WeekDay(Date2, vbMonday) - 1
  22. If iWeekday1 > 4 Then iWeekday1 = 4
  23. If iWeekday2 > 4 Then iWeekday2 = 4
  24.  
  25. lWeeks = DateDiff("w", Date1, Date2)
  26.  
  27. If iWeekday1 <= iWeekday2 Then
  28. lDateDiff = (lWeeks * 5) + (iWeekday2 - iWeekday1)
  29. Else
  30. lDateDiff = ((lWeeks + 1) * 5) - (iWeekday1 - iWeekday2)
  31.  
  32. End If
  33.  
  34. BusinessDateDiff = lDateDiff
  35.  
  36. End Function

Report this snippet  

You need to login to post a comment.