LoginSignup
7
7

More than 5 years have passed since last update.

phpで第2土曜日や第4土曜日を取得する

Last updated at Posted at 2015-05-25

phpで第2土曜日を取得するには、
<?php
echo date("Y年 n月j日", strtotime('second sat of this month'));
?>

で, 2015年 5月16日 と出力される。
これで次の第2土曜日を得る関数ができた。

next_2_sat_day.php
function next_2_sat_gatu_hi(){
if ( intval(date("Ymd")) <= intval(date("Ymd", strtotime('second sat of this month')))) {
            return date("Y年 n月j日", strtotime('second sat of this month'));
} else {
            return date("Y年 n月j日", strtotime('second sat of next month'));
    }
}

echo next_2_sat_gatu_hi();

呼び出し結果、2015年 5月26日に実行すると
2015年 6月13日
となる。

参考にしたサイト:
http://php.net/manual/ja/datetime.formats.relative.php
http://php.net/manual/ja/function.date.php

7
7
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
7
7