'd-m-Y', "day" => 'Mon|Tue|Wed|Thu|Fri|Sat|Sun', "date_in_year" => 'd-m', ], // ... ] */ public static function get_date_range($from_date, $to_date = ''){ if(!$to_date) $to_date = $from_date; $periods = new \DatePeriod( new \DateTime(static::reverse_date($from_date)), new \DateInterval('P1D'), new \DateTime(static::reverse_date($to_date)) ); $range = []; foreach ($periods as $key => $value) { $range[] = [ "date" => $value->format('d-m-Y'), "day" => $value->format('D'), "date_in_year" => $value->format('d-m'), ]; } $to_date_time = strtotime(static::reverse_date($to_date)); $range[] = [ "date" => $to_date, "day" => date("D", $to_date_time), "date_in_year" => date("d-m", $to_date_time), ]; return $range; } /** * @param $from_date string dd-mm-YYYY * @param $to_date string dd-mm-YYYY * @return int number of days */ public static function get_day_diff($from_date, $to_date) { $now = strtotime(static::reverse_date($to_date)); $your_date = strtotime(static::reverse_date($from_date)); $datediff = $now - $your_date; return round($datediff / (60 * 60 * 24)); } /** * @param $date string dd-mm-YYYY * @param $num_days int * @return string dd-mm-YYYY */ public static function add_day($date, $num_days = 1) { return date('d-m-Y', strtotime(static::reverse_date($date). ' + '.$num_days.' days')); } //Reverse date from yyyy-mm-dd to dd-mm-yyyy public static function reverse_date($p_date) { list($year, $month, $day) = explode("-", $p_date); if(!$year || $year == '0000') return ''; return join("-", [$day, $month, $year]); } public static function getDateTimeForMySQL() { return date("Y-m-d H:i:s"); } /** * @description convert date pattern: dd-mm-YYYY H:i to timestamp * @param string $input_date_time dd-mm-YYYY H:i to timestamp * @return int */ public static function convertDateTimeToInt($input_date_time) { $check_date_pattern = "/\d{2}-\d{2}-\d{4}(\s+)?\d{1,2}:\d{1,2}/i"; $format_date_time = str_replace("/", "-", $input_date_time); if(preg_match($check_date_pattern, $format_date_time)) { list($date, $time) = array_values(array_filter(explode(" ", $format_date_time))); return strtotime($date. " ". $time); } return 0; } }