日付計算のメモ

現在時刻の取得
echo date('Y-m-d H:i:s');

$date = new DateTime();
echo $date->format('Y-m-d H:i:s');

n日後、n日前の日付を求める
echo date('Y-m-d H:i:s', strtotime("+ 7 days"));
echo date('Y-m-d H:i:s', strtotime("- 10 days"));

任意のn日後、n日前の日付を求める
echo date('Y-m-d H:i:s', strtotime("2014-08-12 +7 days"));
echo date('Y-m-d H:i:s', strtotime("2014-08-12 -10 days"));


$date = new DateTime('2014-08-12');
$date->modify('+7 days');

日付の計算には

monthやyearも使える。
記事id:859 / 4797PV

関連記事


Warning: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in /home/session-2/www/02_zatu/system_files/core_sys.php on line 41

Warning: simplexml_load_file(http://www.jigen.xyz/index.xml) [function.simplexml-load-file]: failed to open stream: php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in /home/session-2/www/02_zatu/system_files/core_sys.php on line 41

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.jigen.xyz/index.xml" in /home/session-2/www/02_zatu/system_files/core_sys.php on line 41

Warning: Invalid argument supplied for foreach() in /home/session-2/www/02_zatu/system_files/core_sys.php on line 42