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 7504221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:30:06+00:00 2026-05-29T21:30:06+00:00

I failed to find a proper solution to this issue. As you see in

  • 0

I failed to find a proper solution to this issue. As you see in Example #3 in the PHP documentation, they state that one must beware when adding months using the DateInterval in DateTime::add.

There’s not really any explanation for why the method’s behavior is as such and what I can do to avoid this, which I find to be an error at first sight.

Anyone have some insight into this?

  • 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-29T21:30:07+00:00Added an answer on May 29, 2026 at 9:30 pm

    The issue is that each month can have a different number of days in them. The question is what you’re doing when you want to increment a date by 1 month. Per the PHP documentation if you’re on January 31st (or 30th) and you add 1 month, what is the expected behavior?

    February only has 29 days in it. Do you want to be set to the last day of the month? You’re generally safer incrementing by a set number of days if that’s what you’re looking for, or a static date based on the current date. Without knowing what you’re trying to accomplish when you increment your month, it’s tough to say how to watch for an error.

    EDIT:
    As someone mentions in the similar post commented by Mike B above, you probably want to do something where you (in pseudocode):

     1) Use cal_days_in_month() for the next month and save that number to a variable x
     2) If x >= current billing DOB, increment and be done
     3) DateTime::modify('last day')  (havent used this before but something along these lines) to set the date to the last date of the next month (set it to the 1st of the next month, then last day?)
    

    Worth noting is that if you use the variable here as the new billing value, you’ll wipe out your original value. I would save an extra DB value that’s “first billing date” or just “billing_day_of_month” or something, and use that to figure out the day of month that you should be looking at

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

Sidebar

Related Questions

I have this quite popular problem, but have failed to find a solution that
I have been asked this question, but failed to find an article that describe
This problem is not related to struts 2. I failed to find a solution
ive been googling and failed to find a jquery twitter plugin that is seo
I feel this may be a duplicate but I failed to find a similar
I have tried all possibilities I could, and failed to find solution. Please help
there. I've searched my question around here but failed to find anything relevant. This
I feel this should be exceedingly obvious, but so far I've failed to find
I have failed to find documentation for the operator % as it is used
I read a lot of Q&As here but failed to find a working solution.

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.