Home  >  Article  >  Backend Development  >  PHP获得指定日期所在星期,所在月的第一天和最后一天

PHP获得指定日期所在星期,所在月的第一天和最后一天

WBOY
WBOYOriginal
2016-06-20 13:05:121251browse

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

(1)PHP获得指定日期所在星期的第一天和最后一天,具体代码如下:

<p>function getdays($day){</p>	$lastday=date('Y-m-d',strtotime("$day Sunday"));<br />	$firstday=date('Y-m-d',strtotime("$lastday -6 days"));<br />	return array($firstday,$lastday);<br />}<br /><p>print_r(getdays('2012-06-2'));</p>

(2)PHP获得指定日期所在月的第一天和最后一天

<p>function getdays($day){</p>	$firstday = date('Y-m-01',strtotime($day));<br />	$lastday = date('Y-m-d',strtotime("$firstday +1 month -1 day"));<br />	return array($firstday,$lastday);<br /><br />}<br />print_r(getdays('2012-06-2'));


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP stdClass类使用详解Next article:PHP分页类实现