- //Return the timestamps 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){
- //The calculation formula for the total number of seconds accumulated in each month is: the timestamp seconds on the 1st of the previous month minus the timestamp seconds of the current month
- $d[$i]=trim(date ('Y-m',$start),' ');
- $start+=strtotime('+1 month',$start)-$start;
- $i++;
- }
- return $d;
-
- }
-
- //Return the start and end dates of the week within a time period by passing 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){
- //The calculation formula for the total number of seconds accumulated in each month is: the timestamp seconds on the 1st of the previous month minus the timestamp seconds of the current month
- $d[$i]=trim(date ('Y-m',$start),' ');
- $start+=strtotime('+1 month',$start)-$start;
- $i++;
- }
- return $d;
- }
-
- / /Return the first and last day 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) ;
Copy code
|