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

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

WBOY
Release: 2016-06-20 13:05:12
Original
1281 people have browsed it

分享两个偶尔比较实用的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>
Copy after login

(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'));
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template