转自 代码家园

分享两个偶尔比较实用的PHP函数代码:

(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')); 
文章目录