homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

End of Next Month Date

 4:18 pm on Feb 23, 2008 (gmt 0)

I'm trying to create a date for "the end of next month".


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?




 7:29 pm on Feb 23, 2008 (gmt 0)

Looks like it works - substitute 12 for date("m").


 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.

$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>';

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved