时间:2021-07-01 10:21:17 帮助过:4人阅读
(1)PHP获得指定日期所在星期的第一天和最后一天,具体代码如下:
function getdays($day){
$lastday=date('Y-m-d',strtotime("$day Sunday"));
$firstday=date('Y-m-d',strtotime("$lastday -6 days"));
return array($firstday,$lastday);
}print_r(getdays('2012-06-2'));
(2)PHP获得指定日期所在月的第一天和最后一天
function getdays($day){
$firstday = date('Y-m-01',strtotime($day));
$lastday = date('Y-m-d',strtotime("$firstday +1 month -1 day"));
return array($firstday,$lastday);
}
print_r(getdays('2012-06-2'));