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 2021-12-21

日時によって表示内容を変える

<?php
//タイムゾーンのセット
date_default_timezone_set('Asia/Tokyo');

//date(現在日時)が右辺の日時より前の場合
if (date('Y-m-d H:i') < '2021-12-21 13:00'): ?>

<p>2021年12月21日 13時前です。</p>


<?php 
//date(現在日時)が右辺の日時より前の場合
elseif (date('Y-m-d H:i') < '2021-12-25 17:30'): ?>

<p>2021年12月25日 17時半前です。</p>

<?php else: ?>

<p>2021年12月25日 17時半前を過ぎました</p>

<?php endif; ?>

日本語で曜日を含めて表示させる

$weekDays = array('日', '月', '火', '水', '木', '金', '土');
$today = date('Y年m月d日');
$weekdayIndex = date('w');
$weekday = $weekDays[$weekdayIndex];
$todayWithWeekday = $today . '(' . $weekday . ')';
echo $todayWithWeekday;
// 結果「2023年○月○日(月)」
0
0
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
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?