시간 계산하는법을 알고 싶습니다. > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

시간 계산하는법을 알고 싶습니다. 정보

시간 계산하는법을 알고 싶습니다.

본문

지금 현재 wr_2 에 08:30 wr_4에 10:00 의 데이터가 들어 가 있다고 가정하였을때
wr_4 에서 wr_2를 빼면 02:30 처럼 계산되어 나오게 표현하고 싶습니다.

그러나 wr_4에서 wr_2를 빼버리면 02:00로 계산이 되어져서 나오네요... 나머지 30은 어디에 갔는지.. ㅜ.ㅠ; 제가 초보라서요.. 원문 소스 적어 드리겠습니다.

꼭좀 부탁드립니다.

-----------------------------------------------------------------------------------------

<?
include_once("./_common.php");
//include_once("$g4[path]/lib/latest.lib.php");

$g4['title'] = "기간별 검색화면";
//include_once("$g4[path]/_head.php");
include_once("$g4[path]/head.sub.php");
?>

<? // 이하 프린트 제어관련 스크립터 ?>
<script language="javascript">
// 인쇄보기/페이지설정/인쇄대화상자/인쇄하기 버튼제어
function ieExecWB( intOLEcmd, intOLEparam ){
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
if ( ( ! intOLEparam ) || ( intOLEparam < -1 )  || (intOLEparam > 1 ) )
        intOLEparam = 1;
        WebBrowser1.ExecWB( intOLEcmd, intOLEparam );
        WebBrowser1.outerHTML = "";
}
</script>

<script language=javascript>
// 인쇄 시작전에 실행되는 함수
// 'no'으로 시작하는 div 태그 제거
function window.onbeforeprint()
{
    var divs = document.all.tags("div")
    for (i=0;i<divs.length;i++)
    {
        if (divs[i].id.substring(0,2)== "no") {
        divs[i].style.display = "none";
        }
    }
}

function window.onafterprint()
//인쇄가 종료되면 실행되는 부분
//모든 div 태그를 재생
{
    var divs = document.all.tags("div")
    for (i=0;i<divs.length;i++)
    {
        divs[i].style.display = "inline"
    }
}
</script>

<? // 페이지 넘김/다음페이지로 ?>
<STYLE TYPE="text/css">
    <!-- .break {page-break-before: always;} -->
</STYLE>

<? /*
인쇄 버튼 누를 필요없이 자동으로 인쇄.
------------------------------
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function printPage() {
window.print();
}
// print -->
</script>
<body OnLoad="printPage()">
-------------------------------
*/ ?>

<? // 여기까지 프린터 제어 관련 스크립터 ?>




<?
 
// if (!$fr_date)    $fr_date = "00000000"; // 처음부터 검색
if (!$fr_date)    $fr_date =  date("Ymd", time());
if (!$to_date)   $to_date = date("Ymd", time());
if ($sort1 == "") $sort1 = "wr_1";
    if ($sort2 == "") $sort2 = "asc"; //desc

    $sql  = " select * from g4_write_$bo_table ";

if ($fr_date && $to_date)
{
$sql .= " WHERE (wr_1 between '$fr_date' and '$to_date') ";
}

if ($gubun) { $sql .= " AND ca_name like '$gubun' "; }

if ($gubun2) { $sql .= " AND wr_9 like '$gubun2' "; }


  $sql .= " order by $sort1 $sort2 ";
$result = sql_query($sql);
$total_count = mysql_num_rows($result);

//$rows = $config[cf_page_rows];
$rows = 500; // 한화면에 나올 게시물수 합계를 보기위해 많이잡음.인쇄시 페이지 나눔.
    $pagerows    = 30; // 페이지당 인쇄 라인수
    $printpage  = ceil($total_count / $pagerows); //인쇄페이지수
    $firstpage  =  0;

$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함

$rank = ($page - 1) * $rows;

$sql = $sql . " limit $from_record, $rows ";
$result = sql_query($sql);

$qstr = "page=$page&sort1=$sort1&sort2=$sort2";
$qstr1 = "fr_date=$fr_date&to_date=$to_date&sel_ca_id=$sel_ca_id";


?>
<!-- 테스트 영역 끝 2012-01-20 -->



<div id="noPrint1"> <? // 인쇄시 미포함 영역 1 ?>

<!-- 메인화면 최신글 시작 -->
<table width=750 border=0 cellpadding=0 cellspacing=0 align=center>
<form name=flist>
<? /* <form name=flist method=get style="margin:0px;"> */ ?>
<input type=hidden name=doc  value="<?=$doc?>">
<input type=hidden name=sort1 value="<?=$sort1?>">
<input type=hidden name=sort2 value="<?=$sort2?>">
<input type=hidden name=page  value="<?=$page?>">
<input type=hidden name=bo_table value="<?=$bo_table?>">

<tr><td colspan=3 height=20 ></td></tr>
<tr>
    <td colspan=3>
        &nbsp;&nbsp;<font color=#002fc6 size=3><b> | 기간별 내역 조회 |</b></font>
        &nbsp;&nbsp;<!--<a href="<?=$board_skin_path?>/no_ok.php?bo_table=<?=$bo_table?>"><font color=green>|미결재검색|</font></a>-->
    <input type=button value="프린트" onclick="window.print()">
        <input type=button value="창닫기" onclick="javaScript:self.close()">
    </td>
</tr><p>
<!--
<tr>
    <td colspan=3 align=right>
        <input type=button value="인쇄보기" onclick="window.ieExecWB(7)">
        <input type=button value="Page설정" onclick="window.ieExecWB(8)">
        <input type=button value="대화상자" onclick="window.ieExecWB(6)">
        <input type=button value="인쇄하기" onclick="window.ieExecWB(6, -1)">
        &nbsp;
        <input type=button value="프린트" onclick="window.print()">
        <input type=button value="창닫기" onclick="javaScript:self.close()">
    </td>
</tr>
-->
<tr><td colspan=3 height=10 ></td></tr>
<tr>
    <td width=10%>
        <a href='<?=$_SERVER[PHP_SELF]?>?bo_table=<?=$bo_table?>'>처음</a>
</td>
    <td width=70% align=center>
        검색기간 :  <input type=text name=fr_date size=8 maxlength=8 itemname='기간' required value='<?=$to_date?>'> ~
                <input type=text name=to_date size=8 maxlength=8 itemname='기간' required value='<?=$to_date?>'>

        <? /* <form name="category2" method="get"> */ ?>

        <select name=gubun>
<option value=''>전체</option>
            <option value='외근'>외근</option>
            <option value='외출'>외출</option>
            <option value='연차'>연차</option>
            <option value='조퇴'>조퇴</option>
            <option value='기타'>기타</option>
        </select>
       
<input type="text" name="gubun2" value="<?php echo $gubun2; ?>" size="15" itemname="수정내용" maxlength="20" />

        <!--<script> document.flist.gubun.value = '<?=$gubun?>';</script> -->

        <input type=image src="./img/search_btn.gif" border=0 align=absmiddle>

    </td>
  <td width=20% align=right>건수 : <? echo $total_count ?>&nbsp;</td>
</tr>
<tr><td colspan=3 height=1 bgcolor=#CCCCCC></td></tr>
</table>
<p>
</div> <? // 인쇄시 미포함 영역 1 끝 ?>

<div id="startPrint"> <? // 인쇄영역 시작 ?>

<table width=750 border=0 cellpadding=0 cellspacing=0 align=center>
<?
for ($i=0; $row=mysql_fetch_array($result); $i++)
{
    $num = $rank + $i + 1;

    if($i % 30 == 0) {
        $subpage  = $subpage + 1;

        if($firstpage) {
        echo "
            <tr>
                <td colspan=11>
                    <div style='font-size: 14px; font-family: dotum; font-weight: bold; margin: 5px 0;'>
                    기간별조회 : [$fr_date~$to_date] Page $subpage/$printpage
                    </div>
                </td>
            </tr>
        ";
        } else {
        echo"
            <tr>
                <td colspan=11>
                <div style='font-size: 14px; font-family: dotum; font-weight: bold; margin: 5px 0;'>
기간별조회 : [$fr_date~$to_date] Page $subpage/$printpage
</div>
                </td>
            </tr>
        ";
        }

    $firstpage = 1;

echo "
<tr><td colspan=11 height=3 bgcolor=#0E87F9></td></tr>
<tr height='20px' align='center'>
<font size=1>
<th width='40px' rowspan='2' style='text-align: center; padding-right:5px;'>
번호
</th>
<th width='60px' rowspan='2' style='text-align: center; padding-right:5px;'>
요일
</th>
<th width='40px' rowspan='2' style='text-align: center; padding-right:5px;'>
종류
</th>
<th width='60px' rowspan='2' style='text-align: center; padding-right:5px;'>
이름
</th>
<th width='110px' rowspan='2' style='text-align: center; padding-right:5px;'>
사유
</th>
<th width='60px' rowspan='2' style='text-align: center; padding-right:5px;'>
행선지
</th>
</th>
<th width='60px' rowspan='2' style='text-align: center; padding-right:5px;'>
담당
</th>
<th width='60px' rowspan='2' style='text-align: center; padding-right:5px;'>
연락처
</th>
<th width='90px' rowspan='2' style='text-align: center; padding-right:5px;'>
출발시간
</th>
<th width='100px' rowspan='2' style='text-align: center; padding-right:5px;'>
도착시간
</th>
<th width='50px' colspan='2' style='text-align: right; padding-right:5px;'>
여부
</th></font>


<tr></tr>
";
}

    $list = $i%2;
$row[wr_1] = substr($row[wr_1],2,6);

    // 00000000 날짜를 년월일만 취해서 000000으로 표시
    // 00.00.00 으로 이미 입력된 데이타고려

// 검색내역총계(페이지합)
            $sub_suip1 += $row[wr_3];
            $sub_suip2 += $row[wr_4];
            $sub_jich1 += $row[wr_content];
            $sub_jich2 += $row[wr_6];
            $sub_jich3 += $row[wr_2];

    $sub_sum_total1 = $sub_suip1 - $sub_jich1;
    $sub_sum_total2 = $sub_suip2 - $sub_jich2;
    $sub_sum_total3 = $sub_suip2 - $sub_jich3;


    echo "
    <tr class='list$list center'>
        <td style='width: 40px; text-align:center;'>$num</td>
        <td style='width: 40px; text-align:center;'><font color=#002fc6>$row[wr_6]</font></td>
        <td style='width: 40px; text-align:center;'>$row[wr_5]</td>
        <td style='width: 60px; text-align:center;'>$row[wr_name]</td>
    <td style='width: 110px; text-align:center;'>$row[wr_subject]</td>
        <td style='width: 60px; text-align: center;'>$row[wr_10]</td>
        <td style='width: 60px; text-align: center;'>$row[wr_link1]</td>
        <td style='width: 60px; text-align: center;'>$row[wr_link2]</td>
        <td style='width: 90px; text-align: center;'>$row[wr_1] $row[wr_2]</td>
        <td style='width: 100px; text-align: center;'>$row[wr_3] $row[wr_4]</td>
        <td style='width: 50px; text-align: center;'><font color=red>$row[wr_9]</font></td>
";



echo "
    </tr>
<tr><td colspan=11 height=1 bgcolor=#F5F5F5></td></tr>";
// 라인사이 공백
}

if ($i == 0) {
    echo "<tr><td colspan=11 align=center height=100 bgcolor=#ffffff><span class=point>자료가 한건도 없습니다.</span></td></tr>\n";
}
?>
<tr><td colspan=11 height=1 bgcolor=CCCCCC></td></tr>
</table>
<div style='font-size: 14px; font-family: dotum; font-weight: bold; margin: 15px 0 0 0;'>
    &nbsp;&nbsp;&nbsp;기간별내역 합계 : [<?=$fr_date?> ~ <?=$to_date?>]
</div>
<table width=750 border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
    <td width=50%>&nbsp;</td>
    <td width=50% align=right><?=get_paging($config[cf_write_pages], $page, $total_page, "$_SERVER[PHP_SELF]?bo_table=$bo_table&$qstr1&page=");?></td>
</tr>
</table>
<TABLE width="750" border=1 cellspacing="0" bordercolordark="white" bordercolorlight="black" bordercolor="#cacaca" align=center>
    <tr>
        <td align=center><font color=#002fc6>기간별 합계</font></td>
        <td align=center>시간 합계</td>
    </tr>

    <tr>
        <td align=center>단위 합계</td>
        <td align=right><font color='red' size='2'>&nbsp;&nbsp;<?=number_format($sub_sum_total3)?>시간&nbsp;</b></font></td>
    </tr>

</table>
</td></tr></table>
<!-- 메인화면 최신글 끝 -->

<?
//include_once("$g4[path]/_tail.php");
include_once("$g4[path]/tail.sub.php");
?>

댓글 전체

echo date("Y-m-d",strtotime("now", $time))." 현재";
echo date("Y-m-d",strtotime("+1 day", $time))." 하루 후(내일)";
echo date("Y-m-d",strtotime("+1 week", $time))." 일주일 후";
echo date("Y-m-d",strtotime("-1 month", $time))." 한달 전";
echo date("Y-m-d",strtotime("+1 month", $time))." 다음달";
echo date("Y-m-d",strtotime("+6 month", $time))." 6달후";
echo date("Y-m-d",strtotime("+1 year", $time))." 12달후
와같은 포멧을 연습해보세요.
DateTime::diff -- date_diff — Returns the difference between two DateTime objects

http://kr.php.net/manual/en/function.date-diff.php

This is a very simple function to calculate the difference between two timestamp values.
<?php
function diff($start,$end = false) {
    /*
    * For this function, i have used the native functions of PHP. It calculates the difference between two timestamp.
    *
    * Author: Toine
    *
    * I provide more details and more function on my website
    */

    // Checks $start and $end format (timestamp only for more simplicity and portability)
    if(!$end) { $end = time(); }
    if(!is_numeric($start) || !is_numeric($end)) { return false; }
    // Convert $start and $end into EN format (ISO 8601)
    $start  = date('Y-m-d H:i:s',$start);
    $end    = date('Y-m-d H:i:s',$end);
    $d_start    = new DateTime($start);
    $d_end      = new DateTime($end);
    $diff = $d_start->diff($d_end);
    // return all data
    $this->year    = $diff->format('%y');
    $this->month    = $diff->format('%m');
    $this->day      = $diff->format('%d');
    $this->hour    = $diff->format('%h');
    $this->min      = $diff->format('%i');
    $this->sec      = $diff->format('%s');
    return true;
}

/*
 * How use it?
 *
 * Call your php class (myClass for this example) and use the function :
*/
$start  = strtotime('1985/02/09 13:54:17');
$end    = strtotime('2012/12/12 17:30:21');
$myClass = new myClass();
$myClass->Diff($start,$end);
// Display result
echo 'Year: '.$myClass->Year;
echo '<br />Month: '.$myClass->Month;
echo '<br />Day: '.$myClass->Day;
echo '<br />Hour: '.$myClass->Hour;
echo '<br />Min: '.$myClass->Min;
echo '<br />Sec: '.$myClass->Sec;
// Display only month for all duration
$month = ($myClass->Year * 12) + $myClass->Month;
echo '<br />Total month: '.$month;
// if you want you can use this function without $end value :
$myClass->Diff($start);
// Automatically the end is the current timestamp
?>
wr_2 에 08:30 wr_4에 10:00
wr_4 에서 wr_2를 빼면 02:30 처럼
------------------------------------
시간차 계산은 이런 방법들이 있습니다(더 좋은 방법은 생각이 안나네요)
$tmpdiff=strtotime("2000-01-01 00:00:00") + strtotime($row[wr_4]) - strtotime($row[wr_2]);
$diff_time=date("H:i", $tmpdiff);
echo $diff_time;
===================
$gg=explode(':', $row[wr_2]);
$tmpdiff= strtotime("-{$gg[0]} hour -{$gg[1]} minute", strtotime("2000-01-01 $row[wr_4]"));
$diff_time=date("H:i", $tmpdiff);
echo $diff_time;
전체 66,554 |RSS
그누4 질문답변 내용 검색

회원로그인

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