<?php
//取得某日期為第幾週及該週的第一天跟最後一天
function getweek_fday_lday($thisday){
	//取得thisday 為禮拜幾 0-6
	$weekday = date("w", strtotime($thisday));
	//該週的第一天
	$week_fday = date("Y-m-d", strtotime("$thisday -".$weekday." days"));
	//該週的最後一天
	$week_lday = date("Y-m-d", strtotime("$week_fday +6 days"));
	//回傳 日期,該日期當週的第一天,該日期當週的最後一天
	return array('this_day'=>$thisday,'week_first_day'=>$week_fday,'week_last_day'=>$week_lday);
}

var_dump(getweek_fday_lday(date("Y-m-d")));
?>

結果輸出:
array(3) {
[“this_day”]=> string(10) “2017-06-19”
[“week_first_day”]=> string(10) “2017-06-18”
[“week_last_day”]=> string(10) “2017-06-24”
}

Leave a comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *