日付計算のメモ

現在時刻の取得
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 / 5178PV

関連記事


Warning: simplexml_load_file() [function.simplexml-load-file]: SSL operation failed with code 1. OpenSSL Error messages: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure in /home/session-2/www/02_zatu/system_files/core_sys.php on line 41

Warning: simplexml_load_file() [function.simplexml-load-file]: Failed to enable crypto 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: operation failed 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