728x90

어제, 오늘 날짜를 아래처럼 구하는 것은 잘못된 방법이다.


1
2
3
4
<?
$today = date('Ymd');
$yesterday = $today - 1;
?>
cs


위 결과는 매달 1일이 되었을 때 어제 날짜로 00일을 구한다.

예) 2013-02-01의 어제를 2013-02-00으로 표시.

 

정확히 구하려면 아래 참고.


1
2
3
4
5
6
7
8
9
10
11
12
<?
date("Y-m-d H:i:s", strtotime("-1 day")); // 어제
date("Y-m-d H:i:s", strtotime("now")); // 현재
date("Y-m-d H:i:s", strtotime("+1 day")); // 내일
date("Y-m-d H:i:s", strtotime("+1 week")); // 일주일 후
date("Y-m-d H:i:s", strtotime("-1 month")); // 한달 전
date("Y-m-d H:i:s", strtotime("+1 month")); // 다음달
date("Y-m-d H:i:s", strtotime("+1 week 2 days 3 hours 4 seconds")); // 1주 2일 3시간 4초 후
date("Y-m-d H:i:s", strtotime("next Thursday")); // 다음주 목요일
date("Y-m-d H:i:s", strtotime("last Monday")); // 지난 월요일
date("Y-m-d H:i:s", strtotime("10 September 2013")); // 2013년 9월 10일
?>
cs



출처: http://whiterussian.tistory.com/32 [화이트 러시안]

출처: http://whiterussian.tistory.com/32 [화이트 러시안]

출처: http://whiterussian.tistory.com/32 [화이트 러시안]

출처: http://whiterussian.tistory.com/32 [화이트 러시안]

+ Recent posts