user3274692
user3274692

Reputation: 7

Add days to a date time format

How can i extend a date by days using php. I am using the following code to set joining time for a particular subscription. now i have to add expiry interval which is in days to make for expiryDate and to store it in database. eg: '2014-02-21 07:28:13' + 2 days = '2014-02-23 07:28:13'.

$newSubscription->setJoiningtime(new \DateTime(date('Y-m-d H:i:s')))

Upvotes: 0

Views: 66

Answers (1)

hek2mgl
hek2mgl

Reputation: 157927

Use DateTime::modify(). Like this:

$date = new \DateTime('2014-02-21 07:28:13');
$newSubscription->setJoiningtime($date->modify('+2 days'));

The date() function is not required here.

Upvotes: 1

Related Questions