LoginSignup
34
35

More than 5 years have passed since last update.

【PHP】指定した日の週の週初めの日付を取得するロジック

Posted at

指定した日の週の週初めの日付を取得するロジックですが、とりあえず週始まりを日曜日として考えています。

getBeginningWeekDate.php
public function get_beginning_week_date($ymd) {
    # もし週始まりを月曜日にするなら、$w + 1 にすればいいはずです
    $w = date("w",strtotime($ymd));
    $beginning_week_date =
        date('Y-m-d', strtotime("-{$w} day", strtotime($ymd)));
    return $beginning_week_date;
}
34
35
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
34
35