modify('first day of next month'); // Include the end month $tables = []; while ($start < $end) { $tables[] = $prefix . $start->format('Ym'); $start->modify('+1 month'); } return $tables; } // 获取年份表名 public static function getYearlyTableNames($prefix,$startDate, $endDate){ $startYear = (int)date('Y', strtotime($startDate)); $endYear = (int)date('Y', strtotime($endDate)); $tables = []; for ($year = $startYear; $year <= $endYear; $year++) { $tables[] = $prefix . $year; } return $tables; } /** * 多维数组排序 */ public static function arrSort($data = [],$name='',$sort = 'desc'){ if(!$data || !$name){ return false; } $orders = []; foreach($data as $v){ $orders[] = $v[$name]; } if($sort == 'desc') { array_multisort($orders,SORT_DESC, $data); } else { array_multisort($orders,SORT_ASC, $data); } return $data; } /** * 获取两个日期之间的所有日期 */ public static function getDatesBetween($startDate, $endDate) { $dates = []; $startDate = new \DateTime($startDate); $endDate = new \DateTime($endDate); $endDate->modify('+1 day'); // 添加一天,包含结束日期 $interval = new \DateInterval('P1D'); $dateRange = new \DatePeriod($startDate, $interval, $endDate); foreach ($dateRange as $date) { $dates[] = $date->format('Y-m-d'); } return $dates; } /** * 获取月份差 */ public static function getMonthNum($sdate,$edate){ if($sdate > $edate){ return 0; } list($y1,$m1)=explode("-",date('Y-m',strtotime($sdate))); list($y2,$m2)=explode("-",date('Y-m',strtotime($edate))); return abs(($y2-$y1)*12 + $m2-$m1); } /** * 获取两个日期之间的天数 */ public static function getDays($sdate,$edate){ $days = (strtotime($edate) - strtotime($sdate)) / 86400; return $days; } }