jeeva Posted March 31, 2007 Share Posted March 31, 2007 hi frnds how can i get month difference between two months for example if i have selected 12-2006 and 05-2007 then i need to get the dates like 12-2006,01-2007,02-2007,03-2007,04-2007 and 05-2007. can i get like that? --jeeva Link to comment https://forums.phpfreaks.com/topic/45036-month-difference/ Share on other sites More sharing options...
Jove Posted March 31, 2007 Share Posted March 31, 2007 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 More sharing options...
kenrbnsn Posted March 31, 2007 Share Posted March 31, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.