このコードが計画どおりに機能しないのはなぜですか?
コード:
$regDate = '2016-10-03';
echo $date1 = date('m', strtotime('+4 month', strtotime($regDate))); echo '<br>';
echo $date2 = date('m', strtotime('+4 month', strtotime($date1))); echo '<br>';
echo $date3 = date('m', strtotime('+4 month', strtotime($date2))); echo '<br>';
echo $date4 = date('m', strtotime('+4 month', strtotime($date3))); echo '<br>';
私は戻ってきます:
02 05 05 05
日付を特定できませんでした。最初に日付を計算し、次に日付を計算する必要がありecho
ます。試してみてください-
$regDate = '2016-10-03';
$date1 = strtotime('+4 month', strtotime($regDate));
echo date('m', $date1) . '<br>';
$date2 = strtotime('+4 month', $date1);
echo date('m', $date2) . '<br>';
$date3 = strtotime('+4 month',$date2);
echo date('m', $date3) . '<br>';
$date4 = strtotime('+4 month', $date3);
echo date('m', $date4) . '<br>';
別の簡単な方法は-
$regDate = strtotime('2016-10-03');
foreach(range(1, 4) as $val) {
$regDate = strtotime('+4 month', $regDate);
echo date('m', $regDate) . '<br>';
}
出力
02
06
10
02
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加