0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【PHP】日付から曜日を返す方法

Last updated at Posted at 2022-08-03

使う機会があったのでメモ。

/**
 * 日付を元に曜日(英語)を返す
 *
 * @param string $date 日付 ex.'2022-01-02'
 * @return string 曜日 ex.'sun'
 */
function getDayOfWeek($date) {
    $dayOfWeek = [0 => 'sun', 1 => 'mon', 2 => 'tue', 3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat'];
    return $dayOfWeek[date('w', strtotime($date))];
}

※英語の曜日の場合、もっと簡潔に書く方法をコメントにて教えていただきました。
 ありがとうございます。

0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?