Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Subroutine: Abstract HTML by Phil Paxton
     [next Lesson]  New Features in VBScript version5

Functions -- The WorkingDays function

This page demonstrates how to make a function and display it's results in your page.

   filename=/learn/test/functionworkingdays.asp

<Test Script Below>


<title>functionworkingdays.asp</title>
<body bgcolor="#FFFFFF">
<%
response.write "3 working days from today is " & dtaddWorkingDays(now(),3) & "<p>"
%>
2 working days from today is <%=dtaddWorkingDays(now(),2)%> 
</body>
<%Function dtAddWorkingDays(dtStartDate, nDaystoAdd)
   'Adds working days based on a five day week
   
   Dim dtEndDate
   Dim iLoop
   
   'First add whole weeks
   dtEndDate=DateAdd("ww",Int(nDaysToAdd/5),dtStartDate)
   
   'Add any odd days
   For iLoop = 1 To (nDaysToAdd Mod 5)
      dtEndDate=DateAdd("d",1,dtEndDate)
      'If Saturday increment to following Monday
      If WeekDay(dtEndDate)=vbSaturday Then
      'Increment date to following Monday
      dtEndDate=DateAdd("d",2,dtEndDate)
      End If
   Next
dtAddWorkingDays=dtEndDate
End Function
%>

There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.