PHP method to obtain the previous month, this month, the last 15 days, and the last 30 days

墨辰丷
Release: 2023-03-27 06:26:01
Original
2603 people have browsed it

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 also analyzes the operation skills related to date and timestamp conversion encapsulated by PHP through custom functions in the form of examples. It requires Friends can refer to

for details 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));//获取上个月第一天与最后一天
Copy after login

Running results:

Array ( [firstday] => 20170601 [lastday] => 20170630 )
Copy after login

Related recommendations:

php acquisition timeCode summary sharing

PHP Get Time Difference

# #phpGet timeand day of the week code

# #

The above is the detailed content of PHP method to obtain the previous 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!

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
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!