If you have two date and want to count number of month between them, following is function to count this.
public function countMonthFromDate($date){
$date1 = $date;
$date2 = date('Y-m-d'); $ts1 = strtotime($date1);
$ts2 = strtotime($date2); $year1 = date('Y', $ts1);
$year2 = date('Y', $ts2); $month1 = date('m', $ts1);
$month2 = date('m', $ts2); $diff = (($year2 - $year1) * 12) + ($month2 - $month1);
return $diff;
}
Comments
Post a Comment