• support@answerspoint.com

How can I get a date after 15 days/1 month in PHP?

817

In my PHP code I have a date in my variable "$postedDate".
Now I want to get the date after 7 days, 15 days, one month and 2 months have elapsed.

Which date function should I use?

Output date format should be in US format.

5Answer


0

 

 

Use strtotime.

$newDate = strtotime(' 15 days',$date)

$newDate will now be 15 days after $date. $date is unix time.

http://uk.php.net/strtotime

 

 

  • answered 2 years ago
  • G John

0

try this

$date = date("Y-m-d");// current date

$date = strtotime(date("Y-m-d", strtotime($date)) . "  1 day");
$date = strtotime(date("Y-m-d", strtotime($date)) . "  1 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . "  2 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . "  1 month");
$date = strtotime(date("Y-m-d", strtotime($date)) . "  30 days");

 

  • answered 2 years ago
  • G John

0

This is very simple; try this:

$date = "2013-06-12"; // date you want to upgade

echo $date = date("Y-m-d", strtotime($date ."  1 day") );

 

  • answered 2 years ago
  • G John

0

Try this code to solve :

$date=strtotime(date('Y-m-d'));  // if today :2013-05-23

$newDate = date('Y-m-d',strtotime(' 15 days',$date));

echo $newDate; //after15 days  :2013-06-07

$newDate = date('Y-m-d',strtotime(' 1 month',$date));

echo $newDate; // after 1 month :2013-06-23
  • answered 2 years ago
  • G John

0

Use strtotime.

$newDate = strtotime('+15 days',$date)

$newDate will now be 15 days after $date. $date is unix time.

http://uk.php.net/strtotime

  • answered 2 years ago
  • B Butts

Your Answer

    Facebook Share