出勤情報等、曜日を表示させたい場合を記載します。
今回は日付変更線をズラして朝5時としてみます。
※朝5時までは前日の日付を表示
土曜日(Sat)の場合青、日曜日(Sun)の場合赤としています。
完成イメージ
php コード
//配列を使用し、要素順に(日:0〜土:6)を設定する
$week = [
'Sun', //0
'Mon', //1
'Tue', //2
'Wed', //3
'Thu', //4
'Fri', //5
'Sat', //6
];
//時間算出
$time = date('H');
//日付変更線05なら朝5時
if ($time <= 05 ) {
$date = date("d", strtotime("-1 day"));
$dateeye = date("Ymd", strtotime("-1 day"));
} else {
$date = date('d');
$dateeye = date("Ymd");
}
$date_list1 = date('d', strtotime($dateeye));
$date_list2 = date('d', strtotime("$dateeye +1 day"));
$date_list3 = date('d', strtotime("$dateeye +2 day"));
$date_list4 = date('d', strtotime("$dateeye +3 day"));
$date_list5 = date('d', strtotime("$dateeye +4 day"));
$date_list6 = date('d', strtotime("$dateeye +5 day"));
$date_list7 = date('d', strtotime("$dateeye +6 day"));
$date_week1 = date('w', strtotime($dateeye));
$date_week2 = date('w', strtotime("$dateeye +1 day"));
$date_week3 = date('w', strtotime("$dateeye +2 day"));
$date_week4 = date('w', strtotime("$dateeye +3 day"));
$date_week5 = date('w', strtotime("$dateeye +4 day"));
$date_week6 = date('w', strtotime("$dateeye +5 day"));
$date_week7 = date('w', strtotime("$dateeye +6 day"));
表示側
<h5 style="background-color: #2d2d2d;">出勤情報一覧</h5>
<div class="spcalendar">
<ul class="tab-group">
<li class="tab is-active"><p class="today <?php
if ($week[$date_week1] == 'Sat') {
print 'blue';
} elseif ($week[$date_week1] == 'Sun') {
print 'red';
}
?>"><?php echo $date_list1; ?><span><?php echo $week[$date_week1]; ?></span></p></li>
<li class="tab"><p
<?php
if ($week[$date_week2] == 'Sat') {
print ' class="blue"';
} elseif ($week[$date_week2] == 'Sun') {
print ' class="red"';
}
?>><?php echo $date_list2; ?><span><?php echo $week[$date_week2]; ?></span></p></li>
<li class="tab"><p
<?php
if ($week[$date_week3] == 'Sat') {
print ' class="blue"';
} elseif ($week[$date_week3] == 'Sun') {
print ' class="red"';
}
?>><?php echo $date_list3; ?><span><?php echo $week[$date_week3]; ?></span></p></li>
<li class="tab"><p<?php
if ($week[$date_week4] == 'Sat') {
print ' class="blue"';
} elseif ($week[$date_week4] == 'Sun') {
print ' class="red"';
}
?>><?php echo $date_list4; ?><span><?php echo $week[$date_week4]; ?></span></p></li>
<li class="tab"><p<?php
if ($week[$date_week5] == 'Sat') {
print ' class="blue"';
} elseif ($week[$date_week5] == 'Sun') {
print ' class="red"';
}
?>><?php echo $date_list5; ?><span><?php echo $week[$date_week5]; ?></span></p></li>
<li class="tab"><p<?php
if ($week[$date_week6] == 'Sat') {
print ' class="blue"';
} elseif ($week[$date_week6] == 'Sun') {
print ' class="red"';
}
?>><?php echo $date_list6; ?><span><?php echo $week[$date_week6]; ?></span></p></li>
<li class="tab"><p<?php
if ($week[$date_week7] == 'Sat') {
print ' class="blue"';
} elseif ($week[$date_week7] == 'Sun') {
print ' class="red"';
}
?>><?php echo $date_list7; ?><span><?php echo $week[$date_week7]; ?></span></p></label></li>
</ul>
</div>
.blue {
color: blue;
}
.red {
color: red;
}