프로그래머가 되고 나서 처음으로 달력을 짜보았습니다. > 자유게시판

자유게시판

프로그래머가 되고 나서 처음으로 달력을 짜보았습니다. 정보

프로그래머가 되고 나서 처음으로 달력을 짜보았습니다.

본문

그동안 일하면서 어떻게 달력이 필요 한 작업이 하나도 없었을까요??? 아이러니 하네요 ㅎㅎㅎ

방금 하나 만들어 봤는데 유효한지 모르겠네요~



/*
 * "년, 월, 일"의 초기 값을 설정한다.(전달값이 있을경우 전달값 출력)
 */
$Year = ($_REQUEST['year'])?$_REQUEST['year']:date('Y');
$Month = ($_REQUEST['month'])?str_pad($_REQUEST['month'], 2, 0, STR_PAD_LEFT):date('m');
$Day = ($REQUEST['day'])?str_pad($_REQUEST['day'], 2, 0, STR_PAD_LEFT):date('d');

/*
 * 초기 조건값
 */
$FirstDayWeek = date('w', strtotime($Year.$Month.'01')); // 1일은 몇 요일?
$LastDay = date('t',  strtotime($Year.$Month.'01')); // 몇일까지 있니?
$PreLastDay = date('t', strtotime("-1 month", strtotime($Year.$Month.'01'))); // 지난달은 몇일 까지 있니?
$Day = $PreLastDay - $FirstDayWeek;
$HiddenDate = true;
?>
<div class="reservation">
	<table class="calendar">
		<thead>
			<tr class="week">
				<th scope="col">일요일</th>
				<th scope="col">월요일</th>
				<th scope="col">화요일</th> 
				<th scope="col">수요일</th>
				<th scope="col">목요일</th>
				<th scope="col">금요일</th>
				<th scope="col">토요일</th>
			</tr>
		</thead>
		<tbody class="mon">
			<?php for($m=1; $m<7; $m++) { ?>
			<tr>
				<?php
				for($w=0; $w<7; $w++) {

					if($Day >= $PreLastDay) {

						$HiddenDate = false;
						$Day = 0;
						$PreLastDay = $LastDay;
						$FullDate = '';
					}

					$Day++; // day 증가

					$FullDate = $Year.'-'.str_pad($Month, 2, 0, STR_PAD_LEFT).'-'.str_pad($Day, 2, 0, STR_PAD_LEFT);

					if($HiddenDate || date('w', strtotime($FullDate)) <> $w) {

						$FullDate = '';	
						$HiddenDate = true;
					}
				?>
				<td>
					<div><strong>날짜:</strong> <?php echo $Day; ?></div>
					<div><strong>년.월.일:</strong> <?php echo ($FullDate)?$FullDate:'해당없음'; ?></div>
					<div><strong>당월에 포함된 날짜인지 판단:</strong> <?php echo ($HiddenDate)?'미포함':'포함'; ?></div>
				</td>
				<?php }	?>
			</tr>
			<?php } ?>
		</tbody>
	</table>
</div>

추천
0
  • 복사

댓글 2개

© SIRSOFT
현재 페이지 제일 처음으로