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

  • Home
  • SEARCH
  • 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 6345939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:55:13+00:00 2026-05-24T20:55:13+00:00

I know about the unwanted behaviour of PHP’s function strtotime For example, when adding

  • 0

I know about the unwanted behaviour of PHP’s function

strtotime

For example, when adding a month (+1 month) to dates like: 31.01.2011 -> 03.03.2011

I know it’s not officially a PHP bug, and that this solution has some arguments behind it, but at least for me, this behavior has caused a lot waste of time (in the past and present) and I personally hate it.


What I found even stranger is that for example in:

MySQL: DATE_ADD(‘2011-01-31’, INTERVAL 1 MONTH) returns 2011-02-28
or

C# where new DateTime(2011, 01, 31).AddMonths(1); will return 28.02.2011

wolframalpha.com giving 31.01.2013 + 1 month as input; will return Thursday, February 28, 2013

It sees to me that others have found a more decent solution to the stupid question that I saw alot in PHP bug reports “what day will it be, if I say we meet in a month from now” or something like that. The answer is: if 31 does not exists in next month, get me the last day of that month, but please stick to next month.


So MY QUESTION IS: is there a PHP function (written by somebody) that resolves this not officially recognized bug? As I don’t think I am the only one who wants another behavior when adding / subtracting months.

I am particulary interested in solutions what also work not just for the end of the month, but a complete replacement of strtotime. Also the case strotime +n months should be also dealt with.

Happy coding!

  • 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-24T20:55:14+00:00Added an answer on May 24, 2026 at 8:55 pm

    Here’s the algorithm you can use. It should be simple enough to implement yourself.

    • Have the original date and the +1 month date in variables
    • Extract the month part of both variables
    • If the difference is greater than 1 month (or if the original is December and the other is not January) change the latter variable to the last day of the next month. You can use for example t in date() to get the last day: date( 't.m.Y' )
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know about the mail function in php: mail ($to, $subject, $msg_body,$headers); But since
I know about Application.Exit() but what if I'm not in a windows forms application
I know about M-x dire, but would like to customize it. I would like
I know about covariance, and I know that in general it will not be
I would like to know about how NULL values affect query performance in SQL
I know about the problem and how to fix it. I would like to
I know about perlop. What I am looking for is a quick lookup like
I know about the dependency injection pattern which seems like the best solution available
I know about the not-null attribute. Is there one for enforcing the minimum length
I know about the export->war file I would like something similar to the .jardesc

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.