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 Quote Link to comment 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"); } Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.