This article mainly introduces the method of PHP to simply obtain the last month, this month, the last 15 days, and the last 30 days. It combines the example form to analyze the date and ## encapsulated by PHP through the custom function #Timestamp Conversion related operation skills, friends in need can refer to the following
The example of this article describes the simple method of obtaining the previous month, this month, the last 15 days, and the last 30 days in PHP. Share it with everyone for your reference, the details are as follows:/** * 获取统计时间 * @param $type * 1 上月 * 2 本月 * 3 近15天 * 4 近30天 * @return array */ function getDateInfo($type) { $data = array( array( 'firstday' => date('Ym01', strtotime('-1 month')), 'lastday' => date('Ymt', strtotime('-1 month')), ), array( 'firstday' => date('Ym01', strtotime(date("Y-m-d"))), 'lastday' => date('Ymd', strtotime((date('Ym01', strtotime(date("Y-m-d")))) . " +1 month -1 day")), ), array( 'firstday' => date('Ymd', strtotime("-15 day")), 'lastday' => date('Ymd', strtotime('-1 day')), ), array( 'firstday' => date('Ymd', strtotime("-30 day")), 'lastday' => date('Ymd', strtotime('-1 day')), ), ); return is_null($type) ? $data : $data[$type-1]; } print_r(getDateInfo(1));//获取上个月第一天与最后一天
Array ( [firstday] => 20170601 [lastday] => 20170630 )
The above is the detailed content of PHP method code example to obtain the last month, this month, the last 15 days, and the last 30 days. For more information, please follow other related articles on the PHP Chinese website!