This article mainly introduces the method of PHP to obtain the timestamps of the current month and the beginning and end of the previous month. It involves PHP's judgment and operation skills related to date and time. Friends in need can refer to the following
for details As follows:
Current month
<?php $thismonth = date('m'); $thisyear = date('Y'); $startDay = $thisyear . '-' . $thismonth . '-1'; $endDay = $thisyear . '-' . $thismonth . '-' . date('t', strtotime($startDay)); $b_time = strtotime($startDay);//当前月的月初时间戳 $e_time = strtotime($endDay);//当前月的月末时间戳
Previous month
<?php $thismonth = date('m'); $thisyear = date('Y'); if ($thismonth == 1) { $lastmonth = 12; $lastyear = $thisyear - 1; } else { $lastmonth = $thismonth - 1; $lastyear = $thisyear; } $lastStartDay = $lastyear . '-' . $lastmonth . '-1'; $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)); $b_time = strtotime($lastStartDay);//上个月的月初时间戳 $e_time = strtotime($lastEndDay);//上个月的月末时间戳
The key here is t in the date function, which is used to obtain the number of days in the current month, 28 days, 29 days, 30 days, and 31 days. The number of days it contains is the number at the end of the month.
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
How to insert multiple pieces of data through PHP MySQL
Php multi-process implementation programming example
How to insert data through PHP MySQL
The above is the detailed content of PHP method to obtain the timestamps of the current month and the beginning and end of the previous month. For more information, please follow other related articles on the PHP Chinese website!