Problem with strtotime()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dawid Sza³êga

    Problem with strtotime()

    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


  • Matthias Esken

    #2
    Re: Problem with strtotime()

    Dawid Sza³êga schrieb:
    [color=blue]
    > $month = date('m', strtotime('2004-09-30 +5 months'))
    >
    > This give me 03 (March), but 09 (September) + 5 months should give me 02
    > (February)[/color]

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

    Regards,
    Matthias

    Comment

    • Dawid Szalega

      #3
      Re: Problem with strtotime()

      "Matthias Esken" <muelleimer2004 nospam@usenetve rwaltung.org> wrote in
      message news:cjguuv.1ao .1@usenet.esken .de...[color=blue]
      > There is no such date as 2005-02-30, so you reach the next month.
      > Regards,
      > Matthias[/color]

      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


      Comment

      • Matthias Esken

        #4
        Re: Problem with strtotime()

        Dawid Szalega wrote:
        [color=blue]
        > "Matthias Esken" <muelleimer2004 nospam@usenetve rwaltung.org> wrote in
        > message news:cjguuv.1ao .1@usenet.esken .de...
        >[color=green]
        >> There is no such date as 2005-02-30, so you reach the next month.[/color]
        >
        > 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'[/color]

        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

        Comment

        Working...