PHPメモ050:strtotime()で特定の日の前日/翌日を取得する
文字列で特定の日付があって、その日の前日/翌日を取得する場合、今までは
strftime('%Y/%m/%d', strtotime('-1 day', strtotime('2015/01/01'))); strftime('%Y/%m/%d', strtotime('+1 day', strtotime('2015/01/01')));
みたいに strtotime() を2回使って書いていたが、次のように1回で書くことができる
strftime('%Y/%m/%d', strtotime('2015/01/01 -1 day')); strftime('%Y/%m/%d', strtotime('2015/01/01 +1 day'));
こうも書ける。
strftime('%Y/%m/%d', strtotime('yesterday 2015/01/01')); strftime('%Y/%m/%d', strtotime('tomorrow 2015/01/01'));
参考ページ:
PHP: strtotime - Manual
[php] date()とstrtotime()で日時を取得する | きほんのき
【PHP】strtotime で利用できるパラメータいろいろ | バシャログ。
« PHPメモ049:コマンドラインのオプションとコマンドラインでのコードの実行 | Main | [CentOS 6.6]PHPのインストール »
「PHP」カテゴリの記事
- LaravelでHello World とか諸々(2015.05.13)
- Laravel4のインストール(2015.05.06)
- PHPメモ051:includeとrequireの使い分け(2015.06.19)
- CakePHPのインストール(2015.06.14)
- PHPからPDOでPostgreSQLに接続する(2015.06.09)
TrackBack
TrackBack URL for this entry:
http://app.cocolog-nifty.com/t/trackback/26461/60912458
Listed below are links to weblogs that reference PHPメモ050:strtotime()で特定の日の前日/翌日を取得する:
« PHPメモ049:コマンドラインのオプションとコマンドラインでのコードの実行 | Main | [CentOS 6.6]PHPのインストール »
Comments