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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:31:58+00:00 2026-06-07T16:31:58+00:00

Possible Duplicate: increment date by one month I have the following code to sum

  • 0

Possible Duplicate:
increment date by one month

I have the following code to sum dates:

$var1 = date("d/m/Y");
$dia = substr($var1,0,2);
$mes = substr($var1,3,2);
$a_o = substr($var1,6,4);
$date = $a_o."-".$mes."-".$dia;
$new_date = strtotime( "+3 month", strtotime($date));
$new_date = date('d/m/Y', $new_date);
echo $new_date;

That is the normal method I found on php.net but when I tried to change $var1 with another date, for example, '21/07/2020' the result is '31/01/1970', I don’t know what’s wrong. I tried many forms but the result is the same.

How can I fix this? Or what other forms exist to add X months to a date?

  • 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-06-07T16:31:59+00:00Added an answer on June 7, 2026 at 4:31 pm

    Look into the date_add() function that was added for 5.3.0.

    DateTime::add — date_add — Adds an amount of days, months, years,
    hours, minutes and seconds to a DateTime object

    <?php
    $date = new DateTime('2000-01-01');
    $date->add(new DateInterval('P10D'));
    echo $date->format('Y-m-d') . "\n";
    ?> 
    

    There is also the date_modify() function that was added for 5.2.0.

    DateTime::modify — date_modify — Alters the timestamp

    <?php
    $date = new DateTime('2006-12-12');
    $date->modify('+1 day');
    echo $date->format('Y-m-d');
    ?> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I increment a date by one day in Java? I
Possible Duplicate: Explaining post-increment in C# Consider the following C# code:- int i =
Possible Duplicate: Why does this code not increment a counter properly? I have a
Possible Duplicate: Push-Notification Badge auto increment. I have implemented Push Notification for my iPhone
Possible Duplicate: Add a field and insert an increment value I have this table
Possible Duplicate: Simplest way to increment a date in PHP? I am very new
Possible Duplicate: In what order does evaluation of post-increment operator happen? Consider the following
Possible Duplicate: Post Increment and Pre Increment concept? I cant understand how the if
Possible Duplicate: Python: Behaviour of increment and decrement operators >>> a=2 >>> ++a 2
Possible Duplicate: ++ operator in Scala I want to increment an Int variable in

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.