Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

year planner

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
hi,

does anyone have code that will display a year planner in the format

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
Jan
Feb
Mar
Apr
May
...

thanks MG
 
It looks like you want a loop within a loop to build an HTML table.
 
And add an edit box in each square where a day exists.
 
thanks for ideas guys - anyone whos interested thought might post what worked for me - took out error checking
and formatting stuff when posting to show the basics so hope i havent made mistakes!
someone showed me this ages ago - thanks again Damber.

sql -
table [month] has all months of year
table [holbook] has start/end date of holiday
Code:
SELECT CBB.bookst, CBB.bookend, CC.month, CC.monthid 
FROM month AS CC 
LEFT JOIN (SELECT CB.bookst, CB.bookend
FROM holbook AS CB 
WHERE CB.userholid =44 
AND ((cb.bookst BETWEEN '20070101' AND '20071231') 
OR (cb.bookend BETWEEN '20070101' AND '20071231') 
OR (cb.bookst <= '20070101') AND (cb.bookend >= '20071231'))) 
AS CBB 
ON CC.monthid = month(CBB.bookst) 
ORDER BY CC.monthid, CBB.bookst ASC

asp
Code:
'use arrays as theyre great!
Set RS = Conn.Execute(sql)
aBookings = rs.GetRows()
rs.close

Response.Write("<table>")
Response.Write("<tr>")

'first row - 31 days 
Response.Write("<td colspan =2 class = usersml>Month</td>")
for i=0 to 30
Response.Write ("<td class = usersml>" & i & "</td>")
next
Response.Write("</tr>")

monthid = ""  
recCount = 0

'1st loop for month names down left side
for j=0 to UBound(aBookings, 2)
recCount = recCount + 1  
monthtxt = aBookings(2,j)
'monthid is primary key 
monthid = aBookings(3,j)
blanks = 0

'get days in month
call getDaysInMonth(monthid, motyear)

'need this line cos january didnt work??
if monthid = 1 then monthdays = 31

'add leading zeros to months that need them
if monthid < 10 then 
monthid = "0" & monthid
end if

dStartDatemonth = "01/"&monthid&"/"&motyear

Response.Write("<tr bgcolor="& bgcolor & ">")
Response.Write "<td class = mfitsml width =2>"&(monthtxt)& "</td>"

'second loop  
for i=0 to monthdays - 1
dCurrDate = DateAdd("d", i, dStartDatemonth)

'fills blanks at end of rows 	
if monthdays < 31 then
blanks = 31 - monthdays
end if

'blank cell for no holidays	
freestr = "<td class = courtcarfree align=center width=""10""><img src=""images/bookbutfree.gif"" width =10 border=0 align=center></td>"

'no holiday so blank cell	
if isnull(aBookings(0,j)) or isnull(aBookings(1,j)) then
response.Write(freestr)
else
'there is a holiday so show on day
if datediff("d",dCurrDate,(aBookings(0,j))) <= 0 and _
datediff("d", dCurrDate,(aBookings(1,j))) >= 0 then

response.Write "<td class=courtcarlname align=center width=""10"" align=center>HOL</td>"
end if 

else
'bit that checks to see if next holiday is in same month
if ubound(abookings,2) >= j+1 then

if aBookings(2,j+1) = monthtxt then 
if datediff("d", dCurrDate , aBookings(1,j)) <= 0 then 
j = j + 1 
i = i - 1 
else
response.Write(freestr)    
end if
else
response.Write(freestr)
end if
else
response.Write(freestr)
end if

end if

next

'write blank cells for months that have less than 31 days
for x = 1 to blanks
Response.Write("<td bgcolor=""#666666""></td>")
next
	
Response.Write("</tr>")
Next
Response.Write("</table>")

function getDaysInMonth(strMonth,strYear)
dim strDays	 
    Select Case cint(strMonth)
        Case 1,3,5,7,8,10,12:
			strDays = 31
        Case 4,6,9,11:
		strDays = 30
        Case 2:
		if  ((cint(strYear) mod 4 = 0  and  _
                 cint(strYear) mod 100 <> 0)  _
                 or ( cint(strYear) mod 400 = 0) ) then
		  strDays = 29
		else
		  strDays = 28 
		end if	
    End Select 
    
    getDaysInMonth = strDays
	monthdays = strDays
end function
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top