| End of Next Month Date
|
itledi

msg:3582888 | 4:18 pm on Feb 23, 2008 (gmt 0) | I'm trying to create a date for "the end of next month". date("Y-m-d",mktime(0,0,0,date("m")+2,0)); So far I've come up with this. Will this output the zero hour of the next month? What happens if it were December 2008? Would it be the end of January 2009 or 2008? Thanks
|
cameraman

msg:3582994 | 7:29 pm on Feb 23, 2008 (gmt 0) | Looks like it works - substitute 12 for date("m").
|
whoisgregg

msg:3585312 | 7:20 pm on Feb 26, 2008 (gmt 0) | I would a strtotime [php.net] based solution. First build a timestamp of the first second of the current month, then use strtotime to advance two months, then use strtotime to move backward one second. The sample code below illustrates this approach. <?php $first_second_this_month = date('Y').'-'.date('m').'-01'.' 00:00:00'; echo '<p>$first_second_this_month: '.$first_second_this_month.'</p>'; $last_second_next_month = strtotime("-1 second", strtotime("+2 months", strtotime($first_second_this_month))); echo '<p>$last_second_next_month: '.date("Y-m-d H:i:s", $last_second_next_month).'</p>'; ?>
|
|
|
|
|