Calculates the start and end timestamp of each calendar month in the past N months.

Source: Internet
Author: User
Tags month name
This method is applicable to scenarios where you need to analyze data by calendar month without ** calculating the start and end timestamps of each natural month in the past N months, including the number of months in the current month * @ paraminteger $ max, the default value is 6 * @ paramstring $ monthstr. The third subscript of the returned array (the expression of the specific month) * @ returnarray array (starting from month ).

Applicable to scenarios where you need to analyze data by calendar month without/*** calculate the start and end timestamps of each calendar month in the past N months, including the number of months in the current month * @ param integer $ max, the default value is 6 * @ param string $ monthstr. The third subscript of the returned array (the expression of the specific month) * @ return array. each subarray is in the form of array (starting from month ).

Applicable to scenarios where data needs to be analyzed by calendar month <无>
/*** Calculates the start and end timestamps of each natural month in the past N months, including the current month * @ param integer $ max number of months, the default value is 6 * @ param string $ monthstr. The third subscript of the returned array (the expression of the specific month) * @ return array. each subarray is in the form of array (the start timestamp of the month, month End timestamp, month name) */function month_offset ($ max = 6, $ monthstr = 'ym') {if ($ max <= 0) {return false ;} $ base = date ('Y-m-01 '); $ Y = 1; $ mo = array (); $ mo [0] [0] = strtotime ($ base ); $ mo [0] [1] = time (); $ mo [0] [2] = date ('ymm'); while ($ y <$ max) {$ mo [$ y] [0] = strtotime (date (' Y-m-01 ', strtotime ($ base.'-'. $ y. 'month'); $ mo [$ y] [1] = $ y = 1? $ Mo [0] [0]: $ mo [$ Y-1] [0]; $ mo [$ y] [2] = date ($ monthstr, $ mo [$ y] [0]); $ y ++;} return array_reverse ($ mo);} var_export (month_offset (3); exit; /* array (0 => array (0 => 1425139200, 1 => 1427817600, 2 => '123',), 1 => array (0 => 1503, 1 => 1430409600, 2 => '20140901',), 2 => array (0 => 1504, 1 => 1430409600, 2 => '20160901 ',),) [Finished in 0.1 s] */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.