First of next month....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

First of next month....

Post by Todd_Z »

To get the timestamp of the first of the next month, I'm getting the timestamp of the first of this month, using mktime() and date() calls, then add 45 days to get the next month and year, then mktime() again. This seems like a very inefficient way to do it. Just one of those things that won't click,

.... maybe its just cuz its 2:30am....


either way: anyone have a pretty way to do this?
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

Well... If you know what month it is...why don't you just make

Code: Select all

if ($this_month == 12) {
 $year++;
}

$next_month_timestamp = mktime(0,0,0,$this_month + 1, 1, $year);
AshrakTheWhite
Forum Commoner
Posts: 69
Joined: Thu Feb 02, 2006 6:47 am

Post by AshrakTheWhite »

strtotime()
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

I couldn't find the strtotime terminology for 'first of next month'...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

[feyd@home]>php -r "echo date('Y-m-d H:i:s', strtotime(date('Y-m-01').' +1 month'));"
2006-08-01 00:00:00
Post Reply