Subroutine to findout weekend for the whole year

# Thread: Subroutine to findout weekend for the whole year

1. Member
Join Date
Dec 1969
Posts
31

## Subroutine to findout weekend for the whole year

Hi,<BR><BR>I need a subroutine which I will run once a year and it will enter dates of all the weekends(saturday & sunday) of the whole year in to the table. Two fields in the table date and day. Does anyone know of a smart way to go about doing this...<BR><BR>thanks<BR>gaurang

2. MG Guest

## Here you go

I thought this might be a challange but it turned out to be very easy and one one function to add to my library. Vbscript function make this very easy. The function requires two arguments, year and if it is a leap year or not as true or false.<BR><BR>&#060;% <BR>function listweekenddates(yr, leapyr)<BR> dim dt, daynbr, daysinyr, x<BR> yr = 2000<BR> dt = "1/1/" & yr<BR> dt = cdate(dt) &#039convert to date format<BR> leapyr = true<BR> <BR> if leapyr = true then<BR> daysinyr = 366<BR> else<BR> daysinyr = 365<BR> end if<BR> x = "&#060;table border=1 cellpadding=2 cellspacing=0&#062;"<BR> For i = 1 to 365<BR> <BR> daynbr = Weekday(dt)<BR> if daynbr = 1 or daynbr = 7 then<BR> x = x & "&#060;tr&#062;"<BR> <BR> if daynbr = 1 then<BR> x = x & "&#060;td&#062;Sunday:&#060;/td&#062;"<BR> else <BR> x = x & "&#060;td&#062;Saturday:&#060;/td&#062;"<BR> end if<BR> <BR> x = x & "&#060;td&#062;" & dt & "&#060;/td&#062;"<BR> x = x & "&#060;/tr&#062;"<BR> end if<BR> dt = dateadd("d",1,dt)<BR> <BR> Next<BR> x = x & "&#060;/table&#062;"<BR> listweekenddates = x<BR>end function<BR> <BR> response.write listweekenddates(2000, true)<BR>%&#062;

3. MG Guest

## Wait .... This one is better !!!

This version will check for leap year on its own and does the same function with less code.<BR><BR>&#060;% <BR>function listweekenddates(yr)<BR> dim dt, daynbr, daysinyr, x<BR> dt = "1/1/" & yr &#039create the first day of the year<BR> dt = cdate(dt) &#039convert to date format<BR> <BR> x = "&#060;table border=1 cellpadding=2 cellspacing=0&#062;"<BR> do while datepart("yyyy",dt) = yr <BR> daynbr = Weekday(dt)<BR> <BR> If daynbr = 1 or daynbr = 7 then<BR> Select case daynbr<BR> case 1 x = x & "&#060;tr&#062;&#060;td&#062;Sunday:&#060;/td&#062;"<BR> case 7 x = x & "&#060;tr&#062;&#060;td&#062;Saturday:&#060;/td&#062;"<BR> end select<BR> x = x & "&#060;td&#062;" & dt & "&#060;/td&#062;&#060;/tr&#062;"<BR> end if<BR> <BR> dt = dateadd("d",1,dt)<BR> loop<BR> x = x & "&#060;/table&#062;"<BR> listweekenddates = x<BR>end function<BR> <BR> response.write listweekenddates(1999)<BR>%&#062;

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•