You are here: Re: date("m") question « All PHP « IT news, forums, messages
Re: date("m") question

Posted by robert on 09/28/84 11:48

"ivan" <pc@moosewebdesign.com> wrote in message
news:BWVcg.443815$ze.11832446@phobos.telenet-ops.be...
| Hello,
|
| just one small question concerning 'previous month':
|
| the function date ("m") gives me the current month.
|
| So, date("m")-1 returns the previous month.
|
| But, if the current month is "01", will this return "12" or "00" ?
|
| Tx,
| Ivan.

ivan, you'll get into all sorts of nasty stuff doing "date math" that way.

try this:

$thisMonth = strtotime(date('m') . '/01/' . date('Y'));
$lastMonth = strtotime('-1 month', $thisMonth);
$nextMonth = strtotime('+1 month', $thisMonth);

print_r(
array(
'this month: ' => date('m', $thisMonth) ,
'last month: ' => date('m', $lastMonth) ,
'next month: ' => date('m', $nextMonth)
)
);

hth,

me

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация