Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current date + 2 months

Tags:

I wrote this piece of code in order to display the current date + 2 months :

<?php     $date = date("d/m/Y");     $date = strtotime(date("d/m/Y", strtotime($date)) . "+2 months");     $date = date("d/m/Y",$date);     echo $date; ?> 

It does not seem to work as it displays : 01/03/1970.

What am I doing wrong?

Thanks for your help.

EDIT :

After reading comments and answers, I simplified and corrected it.

<?php     $date = date("d/m/Y", strtotime(" +2 months"));     echo $date; ?> 
like image 294
morgi Avatar asked May 14 '12 15:05

morgi


People also ask

How to get date after 3 Months in PHP?

$effectiveDate = strtotime(date("Y-m-d", strtotime($effectiveDate)) . "+3 months");

What is Strtotime PHP?

The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.


1 Answers

You're missing the second argument for the second strtotime() call:

echo date('d/m/Y', strtotime('+2 months')); 
like image 81
Alix Axel Avatar answered Oct 10 '22 18:10

Alix Axel