katlurvechoc
katlurvechoc

Reputation: 23

Add in Start and End date using PHP

I would like to know how to add in new start and end date using PHP. this is my current coding:

$startdate = date_create(); echo date_format($startdate, 'Y-m-d'); 

$enddate = date_create(); echo date_format($enddate, 'Y-m-d'); 

$actualdate= strtotime('+1 Week', $enddate); 

The end result will always be the current date and not the one that I've insert in. Please help me. Thanks

Upvotes: 0

Views: 1197

Answers (3)

Sougata Bose
Sougata Bose

Reputation: 31749

You can try this -

echo $startdate = date('Y-m-d'); // current date
echo $enddate = date('Y-m-d', strtotime(' + 1 week')); // date 1 week

O/P

2015-11-04
2015-11-11

Start date manually -

    echo $startdate = date('Y-m-d', strtotime('2015-10-04')); 

Upvotes: 1

mischaZeng
mischaZeng

Reputation: 166

You should use the DateTime class from PHP(>= 5.2.0). Here is an example how to add 1 week of current date:

$startdate = new \DateTime('now');
$startdate->modify('+1 week');
$enddate = $startdate->format('Y-m-d');

echo $enddate;

http://php.net/manual/en/class.datetime.php

Upvotes: 0

Saty
Saty

Reputation: 22532

To add one week in date use

$enddate = date('Y-m-d', strtotime('+1 week'));

Upvotes: 0

Related Questions