phpt날짜계산
예: 날짜1 20150902
날짜2 20150907
날짜1에서 날짜2까지 몇일 남았습니다. PHP 로 어떻게 계산해 내죠 ?
날짜2 - 날짜1 하니깐 월로 넘어가면 문제가 생기더라구요
30일 하고 31이 있어서요
댓글 3개
10년 전
다음부터는 QA 에 남겨주시면 감사하겠습니다.
영카트5에 lib/shop.lib.php 라는 파일에
// 타임스탬프 형식으로 넘어와야 한다.
// 시작시간, 종료시간
function gap_time($begin_time, $end_time)
{
$gap = $end_time - $begin_time;
$time['days'] = (int)($gap / 86400);
$time['hours'] = (int)(($gap - ($time['days'] * 86400)) / 3600);
$time['minutes'] = (int)(($gap - ($time['days'] * 86400 + $time['hours'] * 3600)) / 60);
$time['seconds'] = (int)($gap - ($time['days'] * 86400 + $time['hours'] * 3600 + $time['minutes'] * 60));
return $time;
}
이라는 함수가 있습니다.
이것을 참고하여
<?php
// 타임스탬프 형식으로 넘어와야 한다.
// 시작시간, 종료시간
function gap_time($begin_time, $end_time)
{
$gap = $end_time - $begin_time;
$time['days'] = (int)($gap / 86400);
$time['hours'] = (int)(($gap - ($time['days'] * 86400)) / 3600);
$time['minutes'] = (int)(($gap - ($time['days'] * 86400 + $time['hours'] * 3600)) / 60);
$time['seconds'] = (int)($gap - ($time['days'] * 86400 + $time['hours'] * 3600 + $time['minutes'] * 60));
return $time;
}
$a = strtotime('20150902');
$b = strtotime('20150907');
print_r( gap_time($a, $b) );
?>
이런 코드를 작성하면
Array ( [days] => 5 [hours] => 0 [minutes] => 0 [seconds] => 0 )
와 같이 결과가 출력되는것을 확인하실수 있습니다.
영카트5에 lib/shop.lib.php 라는 파일에
// 타임스탬프 형식으로 넘어와야 한다.
// 시작시간, 종료시간
function gap_time($begin_time, $end_time)
{
$gap = $end_time - $begin_time;
$time['days'] = (int)($gap / 86400);
$time['hours'] = (int)(($gap - ($time['days'] * 86400)) / 3600);
$time['minutes'] = (int)(($gap - ($time['days'] * 86400 + $time['hours'] * 3600)) / 60);
$time['seconds'] = (int)($gap - ($time['days'] * 86400 + $time['hours'] * 3600 + $time['minutes'] * 60));
return $time;
}
이라는 함수가 있습니다.
이것을 참고하여
<?php
// 타임스탬프 형식으로 넘어와야 한다.
// 시작시간, 종료시간
function gap_time($begin_time, $end_time)
{
$gap = $end_time - $begin_time;
$time['days'] = (int)($gap / 86400);
$time['hours'] = (int)(($gap - ($time['days'] * 86400)) / 3600);
$time['minutes'] = (int)(($gap - ($time['days'] * 86400 + $time['hours'] * 3600)) / 60);
$time['seconds'] = (int)($gap - ($time['days'] * 86400 + $time['hours'] * 3600 + $time['minutes'] * 60));
return $time;
}
$a = strtotime('20150902');
$b = strtotime('20150907');
print_r( gap_time($a, $b) );
?>
이런 코드를 작성하면
Array ( [days] => 5 [hours] => 0 [minutes] => 0 [seconds] => 0 )
와 같이 결과가 출력되는것을 확인하실수 있습니다.
foxrain
10년 전
http://bandi225.tistory.com/79
10년 전
간단한 소스 찾아서 이미 수정 하였습니다 ^^
게시판 목록
개발자톡
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1434 |
seoldi
|
10년 전 | 1237 | |
| 1433 |
|
10년 전 | 1435 | |
| 1432 | 10년 전 | 742 | ||
| 1431 |
leeleeleelee
|
10년 전 | 937 | |
| 1430 |
RinaP
|
10년 전 | 799 | |
| 1429 |
|
10년 전 | 1273 | |
| 1428 | 10년 전 | 1124 | ||
| 1427 |
senseme
|
10년 전 | 1412 | |
| 1426 |
|
10년 전 | 1898 | |
| 1425 |
leeleeleelee
|
10년 전 | 1592 | |
| 1424 | 10년 전 | 987 | ||
| 1423 | 10년 전 | 908 | ||
| 1422 |
울라라라우
|
10년 전 | 907 | |
| 1421 | 10년 전 | 919 | ||
| 1420 |
프로그램은어려워
|
10년 전 | 1257 | |
| 1419 |
senseme
|
10년 전 | 1213 | |
| 1418 | 10년 전 | 2125 | ||
| 1417 |
파랑새1597
|
10년 전 | 1232 | |
| 1416 |
파랑새1597
|
10년 전 | 1337 | |
| 1415 |
integrity7
|
10년 전 | 1428 | |
| 1414 | 10년 전 | 992 | ||
| 1413 |
blackkil
|
10년 전 | 1914 | |
| 1412 | 10년 전 | 812 | ||
| 1411 | 10년 전 | 1424 | ||
| 1410 |
멋진남자임
|
10년 전 | 1167 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기