Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7186449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:38:01+00:00 2026-05-28T18:38:01+00:00

Being that the current month/year is January 2012, why does the following code return

  • 0

Being that the current month/year is January 2012, why does the following code return December 2011 and not November 2011?

echo date("F Y", strtotime("-2 months"));

This is on PHP 5.3.0 if it makes a difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:38:02+00:00Added an answer on May 28, 2026 at 6:38 pm

    To get what you are looking for you can use this rather verbose version instead:

    echo date("F Y", strtotime("first day of this month - 2 months"));
    

    The problem with your original version is described in detail here: http://derickrethans.nl/obtaining-the-next-month-in-php.html. Quoted below:

    Over and over again PHP users complain that next month in PHP’s
    date-string parser doesn’t go to the next month, but instead skips to
    the one after next month; like in the following example:

    <?php
    $d = new DateTime( '2010-01-31' );
    $d->modify( 'next month' );
    echo $d->format( 'F' ), "\n";
    ?>
    

    The output of the little script will be March. March obviously doesn’t
    follow January as February is in between. However, the current
    behavior is correct. The following happens internally:

    next month increases the month number (originally 1) by one. This
    makes the date 2010-02-31. The second month (February) only has 28
    days in 2010, so PHP auto-corrects this by just continuing to count
    days from February 1st. You then end up at March 3rd. The formatting
    strips off the year and day, resulting in the output March. This can
    easily be seen when echoing the date with a full date format, which
    will output March 3rd, 2010:

    This is for adding months, but the same applies in reverse when subtracting months; there was no November 31st, so the strtotime method “corrects” it into December 1st.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that being open source does not necessarily makes a program more/less secure
Here is my current question: I'm guessing that my problem (described below) is being
I'm trying to group the following string into three groups. 0:0:Awesome:awesome That being "
I have a problem that confuses my users, being that although an item is
I'm writing an application that runs things to a schedule. Idea being that the
I am trying to determine the size of a UITableCellView. The reason being that
We're being told that fewer HTTP requests per page load is a Good Thing.
In DDD you should never let your entities enter an invalid state. That being
Yes, I know, the archive bit is evil. That being said, is there support
From within a DLL that's being called by a C#.NET web app, how do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.