By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,722 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,722 IT Pros & Developers. It's quick & easy.

Problem with strtotime()

P: n/a
Hi,
I do something like this:
$month = date('m', strtotime('2004-09-30 +5 months'))

This give me 03 (March), but 09 (September) + 5 months should give me 02
(February)

It's bug or I thing wrong?

--
Dawid Szałęga
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Dawid Szałęga schrieb:
$month = date('m', strtotime('2004-09-30 +5 months'))

This give me 03 (March), but 09 (September) + 5 months should give me 02
(February)


There is no such date as 2005-02-30, so you reach the next month.

Regards,
Matthias
Jul 17 '05 #2

P: n/a
"Matthias Esken" <mu******************@usenetverwaltung.org> wrote in
message news:cj**********@usenet.esken.de...
There is no such date as 2005-02-30, so you reach the next month.
Regards,
Matthias


I know, but it should increment only month (I thing so) and take maximum a
day of this month (?)
If I do this as SQL query to PostgreSQL:

SELECT TO_CHAR('YYYY-MM-DD', '2004-09-30' + interval '5 months')

then return '2005-02-28'

Month is Fabruary

--
Dawid Szalega
Jul 17 '05 #3

P: n/a
Dawid Szalega wrote:
"Matthias Esken" <mu******************@usenetverwaltung.org> wrote in
message news:cj**********@usenet.esken.de...
There is no such date as 2005-02-30, so you reach the next month.


I know, but it should increment only month (I thing so) and take maximum a
day of this month (?)
If I do this as SQL query to PostgreSQL:

SELECT TO_CHAR('YYYY-MM-DD', '2004-09-30' + interval '5 months')

then return '2005-02-28'


The documentation at http://www.php.net/manual/en/function.strtotime.php
leads me to the GNU date syntax at
http://www.gnu.org/software/tar/manu..._7.html#SEC115.

There, at chapter 7.6 (Relative items in date strings), you'll find the
following example:

| The fuzz in units can cause problems with relative items. For example,
| `2003-07-31 -1 month' might evaluate to 2003-07-01, because 2003-06-31
| is an invalid date. To determine the previous month more reliably, you
| can ask for the month before the 15th of the current month.

Regards,
Matthias
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.