I need to find the month names and numbers between two dates For the above two variables, how to find out the month numbers, ie) output will goes like this
aug2016,sep2016,oct2016,nov2016,dec2016,jan2017
<?php
$date1 = '2013-11-15';
$date2 = '2014-02-15';
$output = [];
$time = strtotime($date1);
$last = date('M-Y', strtotime($date2));
do {
$month = date('M-Y', $time);
$total = date('t', $time);
$output[] = $month;
$time = strtotime('+1 month', $time);
} while ($month != $last);
echo implode(",", $output);
?>
output
Nov-2013,Dec-2013,Jan-2014,Feb-2014
Try this one
<?php
$var1 = "2016-08-15";
$var2 = "2017-01-31";
$result = '';
while (date('m', strtotime($var1)) != date('m', strtotime($var2))) {
$result .= date('MY',(strtotime('next month',strtotime($var1)))).",";
$var1 = date('Y-m-d',(strtotime('next month',strtotime($var1))));
}
echo trim($result, ",");
?>
Output : Sep2016,Oct2016,Nov2016,Dec2016,Jan2017
Correct me if I'm wrong but, based on the output you provided, it seems what you really want to do is extract a month name from month number.
See this: http://www.php.net/manual/en/function.jdmonthname.php
$monthName = jdmonthname($month, 0);
I think you should be able to take it from there.