LoginSignup
77
78

More than 5 years have passed since last update.

PHPで指定月の月初と月末の日付を取得

Last updated at Posted at 2014-03-07

PHPで指定月の月初と月末の日付を取得するTips。
意外とすぐ出てこなかったので残しておきます。

sample.php
$month = '2014-03'; //nullでも構いません
$firstDate = date('Y-m-d', strtotime('first day of ' . $month));
$lastDate = date('Y-m-d', strtotime('last day of ' . $month));

\$monthがnullの場合には、現在月の月初と月末を取得してくれます。

詳しい解説

http://php.net/manual/ja/datetime.formats.relative.php
↑公式リファレンス

77
78
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
77
78