Jump to content

month difference


jeeva

Recommended Posts

well, I would solve this problem by using timestamps. for expample:

$start=strtotime("2006-12-01");
$end=strtotime("2007-05-01");
for($x=$start;$x<$end){
$x+=86400*32; //No month has more than 31 days, so you're now in the next month
$x=mktime(0,0,0,date("m",$x),1,date("Y",$x)); //now the timestamps points to the first day of the month
echo date("m-Y");
}


Link to comment
https://forums.phpfreaks.com/topic/45036-month-difference/#findComment-218641
Share on other sites

Here's a solution that just uses the strtotime() funciton:

<?php
$test=strtotime("2006-12-01");
$end=strtotime("2007-05-01");
$tmp = array();
while ($test <= $end) {
$tmp[] = date('m-Y',$test);
$test = strtotime("+1 month",$test);
}
echo implode(', ',$tmp);
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/45036-month-difference/#findComment-218657
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.