2018년 10월 18일 목요일

php 두 날짜(시분초)의 차이, 몇 초 차이인지 계산해주는 함수, strtotime


php 두 날짜(시분초)의 차이, 몇 초 차이인지 계산해주는 함수

/* *
 @param $stDateHms : 작은 년-월-일 시:분:초 : 2017-01-01 12:13:03
 @param $etDateHms : 더큰 년-월-일 시:분:초 : 2018-03-03 11:10:12
 @return 초 값, -이면 *-1해서 사용한다 floor(), round() 이용
 */
function fnDateDiffSecond($stDateHms, $etDateHms){
$chaiSeconds = strtotime($stDateHms)-strtotime($etDateHms); // 현재시간에서 작성된 시간을 뺌

// echo date('H시 i분 s초 지났습니다.', $chaiSeconds);

return $chaiSeconds;
}


// 호출 예제
$lcSeconds = fnDateDiffSecond (
fnFormatDate($row2[enter_date], "-")." ".fnFormatHms($row2[enter_hms], ":"),
fnFormatDate($row2[end_date], "-")." ".fnFormatHms($row2[end_hms], ":")
);


댓글 없음:

댓글 쓰기