Page 1 of 1

First of next month....

Posted: Sat Jul 08, 2006 1:31 am
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?

Posted: Sat Jul 08, 2006 3:39 am
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);

Posted: Sat Jul 08, 2006 4:58 am
by AshrakTheWhite
strtotime()

Posted: Sat Jul 08, 2006 8:53 am
by Todd_Z
I couldn't find the strtotime terminology for 'first of next month'...

Posted: Sat Jul 08, 2006 9:23 am
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