PHP time and date processing
- // Returns the timestamp of all months in a time period.
- Function monthList ($ start, $ end ){
- If (! Is_numeric ($ start) |! Is_numeric ($ end) | ($ end <= $ start) return '';
- $ Start = date ('Y-M', $ start );
- $ End = date ('Y-M', $ end );
- // Convert to timestamp
- $ Start = strtotime ($ start. '-01 ');
- $ End = strtotime ($ end. '-01 ');
- $ I = 0;
- $ D = array ();
- While ($ start <= $ end ){
- // Formula for calculating the total number of seconds accumulated here: the timestamp number of seconds in the previous month minus the timestamp number of the current month
- $ D [$ I] = trim (date ('Y-M', $ start ),'');
- $ Start + = strtotime ('+ 1 month', $ start)-$ start;
- $ I ++;
- }
- Return $ d;
- }
- // Returns the start and end dates of a week in a time period. The value belongs to the date type.
- Function monthList ($ start, $ end ){
- If (! Is_numeric ($ start) |! Is_numeric ($ end) | ($ end <= $ start) return '';
- $ Start = date ('Y-M', $ start );
- $ End = date ('Y-M', $ end );
- // Convert to timestamp
- $ Start = strtotime ($ start. '-01 ');
- $ End = strtotime ($ end. '-01 ');
- $ I = 0;
- $ D = array ();
- While ($ start <= $ end ){
- // Formula for calculating the total number of seconds accumulated here: the timestamp number of seconds in the previous month minus the timestamp number of the current month
- $ D [$ I] = trim (date ('Y-M', $ start ),'');
- $ Start + = strtotime ('+ 1 month', $ start)-$ start;
- $ I ++;
- }
- Return $ d;
- }
- // Returns the first and last days of a month.
- Function getthemonth ($ date)
- {
- $ Firstday = date ('Y-m-01 ', strtotime ($ date ));
- $ Lastday = date ('Y-m-D', strtotime ("$ firstday + 1 month-1 day "));
- Return array ($ firstday, $ lastday );
- }
- $ Today = date ("Y-m-d ");
- $ Day = getthemonth ($ today );
|
PHP