PHPで先月の求め方

PHP
print date('n', strtotime('- 1 second ', strtotime(date('Y-m-01'))));

アプローチは、今月の1日から1秒引いた時の月。

strtotime(‘-1 month’); はちゃんと返してくれない!

例えば、7/31の時。

print date('n', strtotime('- 1 month', strtotime(date('2009-07-31')))); // 7が返るからダメ!

コメント