检查上周五是否在PHP的同一周

时间:2014-03-19 23:37:40

标签: php

您好我正在尝试创建一个PHP脚本,根据星期一到星期日的日期显示信息,但是在每个月的最后一个星期五,数据需要与正常星期五不同

示例PHP:

<?php
$today = date('w');
$mtime=1;
$ttime=2;   
$wtime=3;
$thtime=4;
$ftime=5;
$stime=6;
$sutime=0;

echo "<div>";
if($mtime == $today) { echo $monday_fetch; }
if($ttime == $today) { echo $tuesday_fetch; }
if($wtime == $today) { echo $wednesday_fetch; }
if($thtime == $today) { echo $thursday_fetch; }
if($ftime == $today) { echo $friday_fetch; }
if($stime == $today) { echo $saturday_fetch; }
if($sutime == $today) { echo $sunday_fetch; }
echo "</div>";
?>
<ul>
    <li><a href="#">Monday</a></li>
    <li><a href="#">Tuesday</a></li>
    <li><a href="#">Wednesday</a></li>
    <li><a href="#">Thursday</a></li>
    <li><a href="#">Friday</a></li>
    <li><a href="#">Saturday</a></li>
    <li><a href="#">Sunday</a></li>
</ul>

但是,在本周的最后一个星期五,我需要帮助,例如

if("...last friday in month in current week...") { 
    echo $last_friday_fetch; 
} else { 
    echo $friday_fetch 
}

1 个答案:

答案 0 :(得分:1)

您可以使用PHP strtotime()功能。

以下是一个例子:

<?php
    $last_friday = strtotime('last Friday of this month');
    // ...

    // when you're checking if it's the last friday
    if (date("Y-m-d") == date("Y-m-d", $last_friday)) {
        echo "Last friday!";
    }
?>