To count the first and last days of a month in PHP, we can use the strtotime function to convert. Here are two methods for your reference.
The strtotime function is mainly used, it is powerful and supports relative dates
The code is as follows
代码如下 |
复制代码 |
//计算本月第一天和最后一天
$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;
|
|
Copy code |
|
//Calculate the first and last day of this month
$today=date("Y-m-d");
//No need to explain this, just set the first day to No. 1
$firstday = date('Y-m-01', strtotime($today));
//I’ve never seen this syntax before,
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
echo $firstday."
";
echo $lastday;
http://www.bkjia.com/PHPjc/628674.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/628674.htmlTo count the first and last days of a month in PHP, we can use the strtotime function to convert, as described below There are two methods for your reference. Mainly used strtotime function, function...