날짜형식 질문드립니다.

날짜형식 질문드립니다.

QA

날짜형식 질문드립니다.

본문


<?php
include_once('../../../../../common.php');
$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"];
// 날짜체크
$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;
}
//달력 변경시 년, 월 불러오기.
if ($_POST["year"]) {
    $year = $_POST["year"];
}
if ($_POST["month"]) {
    $month = $_POST["month"];
}
$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));
$sca_qstr = ($qstr) ? '&'.$qstr : '';
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;
}
if (isset($year)) {
    $year = preg_replace('/[^0-9_]/i', '', $year);
    $qstr .= '&year=' . urlencode($year);
}
if (isset($month)) {
    $month = preg_replace('/[^0-9_]/i', '', $month);
    $qstr .= '&month=' . urlencode($month);
}
// 요일
$yoil = array("토", "일", "월", "화", "수", "목", "금");
$write_table = $g5['write_prefix'] . $bo_table;
$board = sql_fetch(" select * from {$g5['board_table']} where bo_table = '$bo_table' ");
?>
        <?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>
                <div class="media-body">
                    <ul>
                        <?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];
                                }
                        ?>
                        <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);?>일 <br />오늘 일정은 없습니다.</p>
                    <?php } ?>
                </div>

            </div>
        </div>
        <?php } ?>
    <div style="padding:20px;">
        
        <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>
            <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>
          </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)) {
                $start_day = (substr($row['wr_7'],0,6) <  $now_month) ? 1 : substr($row['wr_7'],6,2);
                $start_day = sprintf("%2.0f" , $start_day);
                $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);
                $row2 = get_list($row, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']);
                for ($s = (int)$start_day; $s <= (int)$end_day; $s++) {
                    $list[$s][] = $row2;
                }
            }
            $temp = 7 - (($lastday[$month]+$dayoftheweek)%7);
            if($temp == 7) $temp = 0;
            $lastcount = $lastday[$month]+$dayoftheweek + $temp;
            for ($iz = 1; $iz <= $lastcount; $iz++) {
                $is_today = ($b_year == $year && $b_mon == $month && $b_day == $cday) ? true : false;
                $daycolor = ' black';
                $dayweek = $iz%7;
                if($dayweek == 1) {
                    echo '<li class="list-item">'.PHP_EOL;
                    $daycolor = ' red';
                } else if($dayweek == 0) {
                    $daycolor = ' blue';
                }
                //음력날짜
                $myarray = soltolun($year,$month,$cday);
                $daytext = ($is_today) ? '<span class="font-14 orangered"><i data-feather="calendar" class="svg_s"></i></span>' : $cday;  
                $do_cnt = count($list[$cday]);
                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>
                        <?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 } ?>
                    </div>
                <?php
                    $cday++;
                } else {
                    echo '<div></div>'.PHP_EOL;
                }
                if($iz%7 == 0) echo '</li>'.PHP_EOL;
            }
        ?>
        </ul>
    </div>


여기서 데이타 날짜 형식이 20210101 이렇게 되어야 값을 불러오는데요
2021-01-01  이렇게 년도-월-일  중간에 - 를 넣고싶은데 도저히 안되네요
고수님들 부탁드립니다.

이 질문에 댓글 쓰기 :

답변 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);

 

 

 

균이님 답변감사합니다. 덕분에
달력부분에서 나옵니다. 정말 기쁘네요^^

하지만 상단부분에서 알려주신데로 넣으려니 코드가 맞지가 않아서 안되네요
아래의 상단 글자나오는 부분 한번만 더 부탁드려도 될까요?

정말 답변 감사드립니다.^^


                   <?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];
                                }
                        ?>

$chk_today = $b_year.sprintf("%02d",$b_mon);

==> $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

저장하는 부분까지 수정하려면 다른 파일도 수정해야하구요.

그냥 보여지는 부분은 가능한데.
어느 부분을 얘기하는거죠?

아래는 이렇게 수정 가능합니다.

<?php echo ($is_month)?date("Y-m", G5_SERVER_TIME):date("Y-m-d", G5_SERVER_TIME);?>

답변감사합니다.

지금 제가 사용하는 게시판 글쓰기에서 데이타 날짜 형식이 2021-01-01 입력됩니다.
입력된 값을 불러오려하는데 이 코드에선 20210101 이런 형태만 가져올수있습니다.

고수님들 부탁드립니다.

https://sir.kr/g5_skin/23324?sca=%EC%B5%9C%EC%8B%A0%EA%B8%80&sfl=wr_subject%7C%7Cwr_content&stx=%EB%8B%AC%EB%A0%A5

이 스킨입니다.

데이터 형식을 20210101 으로 해야 읽어옵니다.
제가 사용하는건 일반게시판에서 가져온 달력 형식이라서 2021-01-01 이렇게 입력됩니다.

초보라 뭘 어떻게 잘 알려드리질 못해서 미안합니다. ^^

답변을 작성하시기 전에 로그인 해주세요.
전체 0
QA 내용 검색
  • 개별 목록 구성 제목 답변작성자조회작성일
  • 질문이 없습니다.

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT