날짜형식 질문드립니다. 채택완료
</strong>
<?php
include_once('../../../../../common.php');</p>
<p>$bo_table = $_POST["bo_table"];
$is_today = $_POST["is_today"];
$is_lunar = $_POST["is_lunar"];
$is_target = $_POST["is_target"];
$year = $_POST["year"];
$month = $_POST["month"];</p>
<p>// 날짜체크
$today = getdate();
$b_mon = $today['mon'];
$b_day = $today['mday'];
$b_year = $today['year'];
if($year < 1) { // 오늘의 달력 일때
$month = $b_mon;
$mday = $b_day;
$year = $b_year;
}</p>
<p>//달력 변경시 년, 월 불러오기.
if ($_POST["year"]) {
$year = $_POST["year"];
}
if ($_POST["month"]) {
$month = $_POST["month"];
}</p>
<p>$lastday=array(0,31,28,31,30,31,30,31,31,30,31,30,31);
if($year%4 == 0) $lastday[2] = 29;
$dayoftheweek = date("w", mktime(0,0,0,$month,1,$year));</p>
<p>$sca_qstr = ($qstr) ? '&'.$qstr : '';</p>
<p>if($month == 1) {
$year_prev = $year - 1;
$month_prev = 12;
$year_next = $year;
$month_next = $month + 1;
} else if($month == 12) {
$year_prev = $year;
$month_prev = $month - 1;
$year_next = $year + 1;
$month_next = 1;
} else {
$year_prev = $year;
$month_prev = $month - 1;
$year_next = $year;
$month_next = $month + 1;
}</p>
<p>if (isset($year)) {
$year = preg_replace('/[^0-9_]/i', '', $year);
$qstr .= '&year=' . urlencode($year);
}</p>
<p>if (isset($month)) {
$month = preg_replace('/[^0-9_]/i', '', $month);
$qstr .= '&month=' . urlencode($month);
}</p>
<p>// 요일
$yoil = array("토", "일", "월", "화", "수", "목", "금");</p>
<p>$write_table = $g5['write_prefix'] . $bo_table;</p>
<p>$board = sql_fetch(" select * from {$g5['board_table']} where bo_table = '$bo_table' ");
?></p>
<p> <?php if($is_today){ ?>
<div class="list-today">
<div class="media">
<div class="date-box pull-left" style="margin-right:15px;">
<div class="bg-main text-center" style="padding:12px;">
<i data-feather="calendar" class="svg_m"></i>
</div>
<div class="date-icon">
<?php echo ($is_month)?date("Y.m", G5_SERVER_TIME):date("Y.m.d", G5_SERVER_TIME);?>
</div>
</div></p>
<p> <div class="media-body">
<ul>
<?php
// Today
$i = 0;</p>
<p> if($is_month){
$chk_today = $b_year.sprintf("%02d",$b_mon);
$result = sql_query("select * from $write_table where wr_is_comment = '0' and left(wr_7,6) <= '{$chk_today}' and left(wr_8,6) >= '{$chk_today}' order by wr_id asc");
}else{
$chk_today = $b_year.sprintf("%02d",$b_mon).sprintf("%02d",$b_day);
$result = sql_query("select * from $write_table where wr_is_comment = '0' and left(wr_7,8) <= '{$chk_today}' and left(wr_8,8) >= '{$chk_today}' order by wr_id asc");
}
while ($row1 = sql_fetch_array($result)) {
$row = get_list($row1, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);
$row['href'] = G5_BBS_URL.'/board.php?bo_table='.$bo_table.'&wr_id='.$row['wr_id'].$qstr;</p>
<p> // 링크이동
$row['target'] = '';
if($is_link_target && $row['wr_link1']) {
$row['target'] = $is_link_target;
$row['href'] = $row['link_href'][1];
}
?>
<li>
<a href="<?php echo $row['href'];?>"<?php echo $row['target'];?><?php echo $is_modal_js;?>>
<span<?php echo ($row['wr_3']) ? ' class="'.$row['wr_3'].'"' : '';?>>
<?php echo $row['subject'] ;?>
</span>
<?php if($row['wr_comment']) { ?>
<span class="count orangered"><?php echo $row['wr_comment'];?></span>
<?php } ?>
</a>
</li>
<?php $i++; } ?>
</ul>
<?php if(!$i) { ?>
<p><?php echo $b_year;?>년 <?php echo sprintf("%02d",$b_mon);?>월 <?php echo sprintf("%02d",$b_day);?>일
오늘 일정은 없습니다.</p>
<?php } ?>
</div></p>
<p>
</div>
</div>
<?php } ?>
<div style="padding:20px;"></p>
<p>
<div class=" ">
<h3 class="lat_title">
<a href="javascript:;" OnClick="getSchedule('<?php echo $year_prev;?>','<?php echo $month_prev;?>')" onfocus="this.blur()" title="<?php echo $month_prev; ?> 월">< </a></p>
<p> <a href="javascript:;" OnClick="getSchedule('<?php echo $year;?>','<?php echo $month;?>')" title="이번달">
<i data-feather="calendar" class="svg_b"></i> <?php echo $year;?>.<?php echo $month;?>
</a>
<a href="javascript:;" OnClick="getSchedule('<?php echo $year_next;?>','<?php echo $month_next;?>')" onfocus="this.blur()" title="<?php echo $month_next; ?> 월"> ></a></p>
<p> </h3>
<a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=<?php echo $bo_table ?>" class="lt_more">
<span class="sound_only"><?php echo $bo_subject ?></span><i data-feather="plus" class="svg_m"></i><span class="sound_only"> 더보기</span>
</a>
</div>
<div class="list-head div-head">
<span class="red">일<span class="pc_view">요일</span></span>
<span>월<span class="pc_view">요일</span></span>
<span>화<span class="pc_view">요일</span></span>
<span>수<span class="pc_view">요일</span></span>
<span>목<span class="pc_view">요일</span></span>
<span>금<span class="pc_view">요일</span></span>
<span class="blue">토<span class="pc_view">요일</span></span>
</div>
<ul class="list-body">
<?php
$cday = 1;
$sel_mon = sprintf("%02d",$month);
$now_month = $year.$sel_mon;
$sca_sql = ($sca) ? "and ca_name = '".$sca."'" : "";
$result = sql_query("select * from {$write_table} where wr_is_comment = '0' and left(wr_7,6) <= '{$now_month}' and left(wr_8,6) >= '{$now_month}' $sca_sql order by wr_id asc");
while ($row = sql_fetch_array($result)) {</p>
<p> $start_day = (substr($row['wr_7'],0,6) < $now_month) ? 1 : substr($row['wr_7'],6,2);
$start_day = sprintf("%2.0f" , $start_day);</p>
<p> $end_day = (substr($row['wr_8'],0,6) > $now_month) ? $lastday[$month] : substr($row['wr_8'],6,2);
$end_day = sprintf("%2.0f" , $end_day);</p>
<p> $row2 = get_list($row, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);</p>
<p> for ($s = (int)$start_day; $s <= (int)$end_day; $s++) {
$list[$s][] = $row2;
}
}</p>
<p> $temp = 7 - (($lastday[$month]+$dayoftheweek)%7);</p>
<p> if($temp == 7) $temp = 0;</p>
<p> $lastcount = $lastday[$month]+$dayoftheweek + $temp;</p>
<p> for ($iz = 1; $iz <= $lastcount; $iz++) {</p>
<p> $is_today = ($b_year == $year && $b_mon == $month && $b_day == $cday) ? true : false;</p>
<p> $daycolor = ' black';
$dayweek = $iz%7;
if($dayweek == 1) {
echo '<li class="list-item">'.PHP_EOL;
$daycolor = ' red';
} else if($dayweek == 0) {
$daycolor = ' blue';
}</p>
<p> //음력날짜
$myarray = soltolun($year,$month,$cday);</p>
<p> $daytext = ($is_today) ? '<span class="font-14 orangered"><i data-feather="calendar" class="svg_s"></i></span>' : $cday; </p>
<p> $do_cnt = count($list[$cday]);</p>
<p> if($dayoftheweek < $iz && $iz <= $lastday[$month]+$dayoftheweek) {
$fr_date = $year.sprintf("%02d",$month).sprintf("%02d",$cday);
?>
<div class="media<?php echo ($is_today) ? ' bg-today' : '';?>">
<a <?php echo ($write_href) ? ' href="'.$write_href.'&fr_date='.$fr_date.'&to_date='.$fr_date.$sca_qstr.'"' : '';?>>
<span class="font-13 pull-left<?php echo $daycolor;?>">
<?php echo $daytext;?>
</span>
<?php if($is_lunar && ($is_today || $do_cnt > 0)){?>
<span class="font-10 pull-right">
<?php echo $myarray['month'].'.'.$myarray['day'];?>
</span>
<?php } ?>
</a></p>
<p> <?php if($do_cnt > 0) { ?>
<div class="do-list font-11" style="margin-top:20px;">
<ul>
<?php
for($i = 0; $i < $do_cnt; $i++) {
// 링크이동
$list[$cday][$i]['target'] = '';
if($is_target && $list[$cday][$i]['wr_link1']) {
$list[$cday][$i]['target'] = $is_target;
$list[$cday][$i]['href'] = $list[$cday][$i]['link_href'][1];
}
if($list[$cday][$i]['subject']){
?>
<li>
<a href="<?php echo $list[$cday][$i]['href'];?>"<?php echo $list[$cday][$i]['target'];?> class="red one_line" title="<?php echo $list[$cday][$i]['subject'] ;?>">
<?php echo $list[$cday][$i]['subject'] ;?>
</a>
</li>
<?php
} //if
}
?>
</ul>
</div>
<?php } ?></p>
<p> </div>
<?php
$cday++;
} else {
echo '<div></div>'.PHP_EOL;
}</p>
<p> if($iz%7 == 0) echo '</li>'.PHP_EOL;
}
?>
</ul>
</div>
<strong>
답변 3개
가장 간단한 방법은 등록시 날짜형식을 맞게해주는 것입니다
위 코드에서 수정은 다음 처럼
$now_month = $year.$sel_mon; ==> $now_month = $year.'-'.$sel_mon;
left(wr_7,6) ==> left(wr_7,7)
left(wr_8,6) ==> left(wr_8,7)
$start_day = (substr($row['wr_7'],0,6) < $now_month) ? 1 : substr($row['wr_7'],6,2);
==> $start_day = (substr($row['wr_7'],0,7) < $now_month) ? 1 : substr($row['wr_7'],8);
$end_day = (substr($row['wr_8'],0,6) > $now_month) ? $lastday[$month] : substr($row['wr_8'],6,2);
==> $end_day = (substr($row['wr_8'],0,7) > $now_month) ? $lastday[$month] : substr($row['wr_8'],8);
답변에 대한 댓글 2개
==> $chk_today = $b_year.'-'.sprintf("%02d",$b_mon);
$chk_today = $b_year.sprintf("%02d",$b_mon).sprintf("%02d",$b_day);
==> $chk_today = $b_year.'-'.sprintf("%02d",$b_mon).'-'.sprintf("%02d",$b_day);
다음은 페이지 전체코드 모두 수정
left(wr_7,6) ==> left(wr_7,7)
left(wr_8,6) ==> left(wr_8,7)
left(wr_7,8) ==> wr_7
left(wr_8,8) ==> wr_8
댓글을 작성하려면 로그인이 필요합니다.
답변감사합니다. 지금 제가 사용하는 게시판 글쓰기에서 데이타 날짜 형식이 2021-01-01 입력됩니다. 입력된 값을 불러오려하는데 이 코드에선 20210101 이런 형태만 가져올수있습니다. 고수님들 부탁드립니다.
답변에 대한 댓글 2개
이 스킨입니다.
데이터 형식을 20210101 으로 해야 읽어옵니다.
제가 사용하는건 일반게시판에서 가져온 달력 형식이라서 2021-01-01 이렇게 입력됩니다.
초보라 뭘 어떻게 잘 알려드리질 못해서 미안합니다. ^^
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
달력부분에서 나옵니다. 정말 기쁘네요^^
하지만 상단부분에서 알려주신데로 넣으려니 코드가 맞지가 않아서 안되네요
아래의 상단 글자나오는 부분 한번만 더 부탁드려도 될까요?
정말 답변 감사드립니다.^^
[code]
<?php
// Today
$i = 0;
if($is_month){
$chk_today = $b_year.sprintf("%02d",$b_mon);
$result = sql_query("select * from $write_table where wr_is_comment = '0' and left(wr_7,6) <= '{$chk_today}' and left(wr_8,6) >= '{$chk_today}' order by wr_id asc");
}else{
$chk_today = $b_year.sprintf("%02d",$b_mon).sprintf("%02d",$b_day);
$result = sql_query("select * from $write_table where wr_is_comment = '0' and left(wr_7,8) <= '{$chk_today}' and left(wr_8,8) >= '{$chk_today}' order by wr_id asc");
}
while ($row1 = sql_fetch_array($result)) {
$row = get_list($row1, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);
$row['href'] = G5_BBS_URL.'/board.php?bo_table='.$bo_table.'&wr_id='.$row['wr_id'].$qstr;
// 링크이동
$row['target'] = '';
if($is_link_target && $row['wr_link1']) {
$row['target'] = $is_link_target;
$row['href'] = $row['link_href'][1];
}
?>
[/code]