Heojju

[PHP] strtotime 함수 본문

웹개발/PHP

[PHP] strtotime 함수

우주별 2016. 12. 6. 16:44

strtotime 함수


int 형 함수로 날짜, 시간을 계산할 때 사용합니다.



1. 표현


<?php

echo strtotime("now"), "\n"; // 현재

echo strtotime("10 September 2000"), "\n"; // 2000년 9월 10일

echo strtotime("+1 day"), "\n"; // 하루 후

echo strtotime("+1 week"), "\n"; // 일주일 후

echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; // 1주 2일 4시간 2초 후

echo strtotime("next Thursday"), "\n"; // 다음주 목요일

echo strtotime("last Monday"), "\n"; // 저번주 월요일

echo date( "Y-m-d", strtotime( "2009-01-31 +1 month" ) ); // PHP:  2009-02-31

?> 



2. 날짜 간의 계산(날짜 더하기 빼기)


<?php

$date = "2016-12-25";


$today = date("Y-m-d", time());


$result = ((strtotime($date) - strtotime($today))/86400); // 86400 (60초*60분*24시)


echo $result."일";

?> 


결과 값은 "19일" 이 나옵니다.