Hey I've always been fuzzy on this simple matter
If I do
$month = date("m"+1);
And it's December, it will just set it back to 1, right? I can't really test it since it's not December.
$month = date("m", strtotime("+1 month"));
NogDog;10879966 wrote:$month = date("m", strtotime("+1 month"));
Actually, due the peculiarities of date arithmetic, that will give you problems when the current month's day is greater than the last day of the next month. Therefore, it might be better to do:
$month = date('m') + 1; if(month > 12) { $month = $month - 12; }
How did you find out about that peculiar date thing right after you posted the first solution? I'm curious
Shawazi;10879973 wrote:How did you find out about that peculiar date thing right after you posted the first solution? I'm curious
I'd seen it before in a another forum, but didn't remember it until after I submitted my first reply.
People don't utilize mktime enough here.. I wonder why?
date( "m", mktime( 0, 0, 0, date("m")+1, 1, date("Y") ) );
You could even pretend it's December
date( "m", mktime( 0, 0, 0, 12+1, 1, date("Y") ) );
ah that's the + 1 solution I was thinking of
m@tt;10879993 wrote:People don't utilize mktime enough here.. I wonder why? date( "m", mktime( 0, 0, 0, date("m")+1, 1, date("Y") ) );
I considered doing that, but I'm just not too crazy about the overhead of 4 separate function calls instead of one with some very simple arithmetic. But that's just me. 🙂