반응형
Classic ASP에서 간단하게 달력을 만드는 예제입니다.
CSS는 간단하게 적용했으니 원하는 디자인으로 커스텀하시면 됩니다.
<html>
<head>
<title>ASP 달력 만들기</title>
<style>
table, td {
border : 1px, solid black;
border-collapse : collapse;
}
</style>
</head>
<body>
<%
'-------------------------------------------------------------
' 달력만드는 순서
' 1. 이번달 1일의 요일을 계산한다.
' 2. 이번달의 마지막 날짜를 계산한다. (이번달 날짜수 = 다음달 1일 - 이번달 1일)
' 3. 이번 달 1일의 요일을 계산해서 해당셀에 1부터 차례대로 날짜수 만큼 뿌린다.
'-------------------------------------------------------------
'이번달 1일의 요일계산
'-------------------------------------------------------------
NowYear = Request("select_y")
NowMonth = Request("select_m")
If NowYear = "" Then
NowYear = year(now) '금년도
End If
If NowMonth = "" Then
NowMonth = month(now) '금월
End If
NYear = year(now)
NMonth = month(now)
NDay = Day(now)
%>
<center>
<form name="Q_form" method="post" action="calendar_basic.asp">
<select name="select_y">
<option value="" >년도</option>
<option value="2023" <% if NowYear = "2023" then %> selected<% end if %>>2023</option>
<option value="2024" <% if NowYear = "2024" then %> selected<% end if %>>2024</option>
<option value="2025" <% if NowYear = "2025" then %> selected<% end if %>>2025</option>
<option value="2026" <% if NowYear = "2026" then %> selected<% end if %>>2026</option>
<option value="2027" <% if NowYear = "2027" then %> selected<% end if %>>2027</option>
</select>
<select name="select_m">
<option value="">월</option>
<option value="1" <% if NowMonth = "1" then %> selected<% end if %>>1월</option>
<option value="2" <% if NowMonth = "2" then %> selected<% end if %>>2월</option>
<option value="3" <% if NowMonth = "3" then %> selected<% end if %>>3월</option>
<option value="4" <% if NowMonth = "4" then %> selected<% end if %>>4월</option>
<option value="5" <% if NowMonth = "5" then %> selected<% end if %>>5월</option>
<option value="6" <% if NowMonth = "6" then %> selected<% end if %>>6월</option>
<option value="7" <% if NowMonth = "7" then %> selected<% end if %>>7월</option>
<option value="8" <% if NowMonth = "8" then %> selected<% end if %>>8월</option>
<option value="9" <% if NowMonth = "9" then %> selected<% end if %>>9월</option>
<option value="10" <% if NowMonth = "10" then %> selected<% end if %>>10월</option>
<option value="11" <% if NowMonth = "11" then %> selected<% end if %>>11월</option>
<option value="12" <% if NowMonth = "12" then %> selected<% end if %>>12월</option>
</select>
<input type="submit" name="b2" value="조회">
</form>
<%
Yoil = weekday(NowYear & "-" & NowMonth & "-1") '1:일요일 2:월요일 ....7:토요일
'이번달 마지막날 찾기
'----------------------------------------------------------------------
'이번달 1일
NowMonthFirst = NowYear & "-" & Right(("00" & Nowmonth),2) & "-01"
'다음달 1일
NextMonthFirst = DateAdd("m",1,NowMonthFirst)
'(다음달 1일) - (이번달 1일 ) = 이번달 마지막날짜
LastNowMonth = DateDiff("y", NowMonthFirst, NextMonthFirst)
'DB 날짜 조회용 변수
'-------------------------------------------------------------
q1 = DateSerial(NowYear, NowMonth, 1)
q2 = DateSerial(NowYear, NowMonth, LastNowMonth)
%>
<table>
<tr height="40" align="center">
<td width="200"><font size="4" color="red"><b>일</b></font></td>
<td width="200"><font size="4"><b>월</b></font></td>
<td width="200"><font size="4"><b>화</b></font></td>
<td width="200"><font size="4"><b>수</b></font></td>
<td width="200"><font size="4"><b>목</b></font></td>
<td width="200"><font size="4"><b>금</b></font></td>
<td width="200"><font size="4" color="blue"><b>토</b></font></td>
</tr>
<tr height="130">
<%
'1일이 시작하기 전 빈칸 생성
For weekdaycount = 1 to Yoil-1
Response.write "<td></td>"&chr(13)
Next
'1일부터 마지막날까지 달력생성
'------------------------------
For i = 1 to LastNowMonth
If Yoil = 1 Then
%>
<% If Cdbl(NowYear) = Cdbl(NYear) and Cdbl(NowMonth) = Cdbl(NMonth) and Cdbl(i) = Cdbl(NDay) Then%>
<td bgcolor="#90EE90">
<% Else %>
<td>
<% End If %>
<font color='red'>
<b>
<% = i %>
</b>
</font>
<br><br><br><br>
</td>
<% ElseIf Yoil = 7 Then %>
<% If Cdbl(NowYear) = Cdbl(NYear) and Cdbl(NowMonth) = Cdbl(NMonth) and Cdbl(i) = Cdbl(NDay) Then%>
<td bgcolor="#90EE90">
<% Else %>
<td>
<% End If %>
<font color='blue'>
<b>
<% = i %>
</b>
</font>
<br><br><br><br>
</td>
<% Else %>
<% If Cdbl(NowYear) = Cdbl(NYear) and Cdbl(NowMonth) = Cdbl(NMonth) and Cdbl(i) = Cdbl(NDay) Then%>
<td bgcolor="#90EE90">
<% Else %>
<td>
<% End If %>
<b>
<% = i %>
</b>
<br><br><br><br>
</td>
<%
end if
'이번달 첫번째 요일 숫자를 증가시켜서 7이 넘으면 줄바꾸기를 하고 요일 숫자를 1로 바꾼다.
Yoil = Yoil + 1
'Response.write Yoil
if Yoil > 7 then
response.write " </tr>" & chr(13)
Response.write " <tr height='130'>"
Yoil = 1
end if
Next
'마지막날 이후 달력 끝날때까지 빈칸 생성(토요일로 끝나면 출력안됨)
'------------------------------------------
If Yoil > 1 Then
for i = Yoil to 7
response.write " <td> </td>"
next
End If
'테이블 닫기
response.write " </tr>" & chr(13) & "</table>"
%>
</body>
</html>
반응형
'웹 개발 > Classic ASP' 카테고리의 다른 글
[Classic ASP] 서버, 클라이언트 정보 조회하는 방법 (IP/접속 포트/도메인) (0) | 2025.09.23 |
---|---|
[Classic ASP] 데이터형 변환 함수 (ASP 내장 함수) (0) | 2025.09.16 |
[ASP] Classic ASP 캐싱 방지 / 웹 페이지 최신화 유지하는 방법 (0) | 2025.08.25 |
[ASP] 한글이 깨져서 나오는 경우 해결 방법 (인코딩 변경) / Oracle, MySQL 등 DB 사용하면 한글 깨짐 (1) | 2025.08.18 |