2016-11-10 47 views

回答

0

糾正我,如果我錯了,但根據您提供的輸出,似乎你真正想要做的是從月份數中提取月份名稱。

看到這個:http://www.php.net/manual/en/function.jdmonthname.php

$monthName = jdmonthname($month, 0); 

我想你應該能夠把它從那裏。

1
<?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); 
?> 

輸出

Nov-2013,Dec-2013,Jan-2014,Feb-2014 
+0

是的!這就是我想要的,thnakū – askm3

1

試試這個

<?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, ","); 
?> 

輸出:Sep2016,Oct2016,Nov2016,Dec2016,Jan2017

相關問題