Get the First or Last Friday in a Month

后端 未结 12 2327
有刺的猬
有刺的猬 2020-11-29 12:12

I\'m trying to write a calendar function like this

function get_date($month, $year, $week, $day, $direction)
{
    ....
}

$week

12条回答
  •  抹茶落季
    2020-11-29 12:47

    This seems to work perfect everytime; it takes any date provided and returns the date of the last friday of the month, even in case of 5 friday in the month.

    function get_last_friday_of_month($inDate) {
        $inDate = date('Y-m-24', strtotime($inDate));
        $last_friday = date('Y-m-d',strtotime($inDate.' next friday'));
        $next_friday = date('Y-m-d',strtotime($inDate.' next friday'));
    
        if(date('m', strtotime($last_friday)) === date('m', strtotime($next_friday))){
            $last_friday = $next_friday;
        }else{
            //
        }
        return $last_friday;
    }
    

提交回复
热议问题