Home > php教程 > php手册 > body text

PHP计算某月的第一天和最后一天

WBOY
Release: 2016-06-13 10:16:57
Original
1413 people have browsed it

在php中要统计某月的第一天和最后一天我们可以使用strtotime函数进行转换,下面介绍两种方法各位朋友可参考。

主要用到了strtotime函数,功能强大,支持相对日期

 代码如下 复制代码

//计算本月第一天和最后一天
$today=date("Y-m-d");
//这个不需要解释吧,直接把第一天设为1号
$firstday = date('Y-m-01', strtotime($today));
//这个语法以前还真没见过,
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
 
echo $firstday."
";
echo $lastday;

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!