Find no if weekend days from 2 given dates..

G

Guest

i am trying to create a function that take 2 SelectedDate from a Calendar and
calculates the no. of days between 2 dates and also calculates the no of
weekends (sundays and saturdays) and at last it gives the difference between
total days minus weekdays..

when i run this script the loop is not ending...my sysytem hangs...

calFromDay.SelectedDate ' from day
calToDay.SelectedDate ' to day

Function ndays(ByVal Fromdate As Date, ByVal Todate As Date)

' define sunday, daterday, ubilice holiday dates
Dim sDay, As Integer
' define total day and total leave and result days.
Dim tday, lday, bday As Integer

'calculate the difference
tday = DateDiff(DateInterval.Day, Fromdate, Todate)
Response.Write("total days " & tday)

'calculate the difference
sDay = 0
While Fromdate <= Todate ' Test value of Counter.

If Weekday(Fromdate) = 1 Or 7 Then
sDay = +1
End If
Fromdate.AddDays(1)
End While
Response.Write("<br><br>Leave days " & sDay)
Response.Write("<br><br>balace is " & (tday -sDay))

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top