homepage Welcome to WebmasterWorld Guest from 54.235.20.17
register, login, search, subscribe, help, library, PubCon, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library : Charter : Moderators: coopster & eelixduppy & jatar k

PHP Server Side Scripting Forum

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

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of Pubcon Inc.
© Pubcon Inc. 1996-2012 all rights reserved