Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zhangguiqiang/2858992 to your computer and use it in GitHub Desktop.
Save zhangguiqiang/2858992 to your computer and use it in GitHub Desktop.
PHP:time_aweek(获取指定日期所在周的开始和结束日期)
function aweek($gdate = "", $first = 0){
if(!$gdate) $gdate = date("Y-m-d");
$w = date("w", strtotime($gdate));
$dn = $w ? $w - $first : 6;
$st = date("Y-m-d", strtotime("$gdate -".$dn." days"));
$en = date("Y-m-d", strtotime("$st +6 days"));
return array($st, $en);
}
function aweek($gdate = "", $first = 0){
if(!$gdate) $gdate = date("Y-m-d");
$w = date("w", strtotime($gdate));
$dn = $w ? $w - $first : 6;
$st = date("Y-m-d", strtotime("$gdate -".$dn." days"));
$en = date("Y-m-d", strtotime("$st +6 days"));
return array($st, $en);
}
#example
#$w = aweek('2011-05-11');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment