user1722857
user1722857

Reputation: 867

How to find date after certain period in php

I am working in yii framework. i am getting current date in php (Yii framework) by-

$date =new CDbExpression('NOW()');

Its giving date in format-"2013-04-27 12:49:27". I want to find date after one year. So how to find date in this format after one year or certain period in php?

Upvotes: 1

Views: 889

Answers (4)

jmarkmurphy
jmarkmurphy

Reputation: 11493

Or try this

$date = new CDbExpression('NOW() + INSTANCE 1 YEAR');

Upvotes: 0

kotanjan
kotanjan

Reputation: 21

You can use alternate which look like this:

$date =new CDbExpression('NOW()');
$NextYear = date('Y-m-d H:i:s',strtotime($date)) . " + 365 day"));

If you want more specific you can try:

$date =new CDbExpression('NOW()');   
$NextYearDate=date('Y-m-d',strtotime('+1 year',$date));

Upvotes: 1

Rikesh
Rikesh

Reputation: 26451

Have a look at DateTime class to manipulate with dates in php.

$newDate = new DateTime($date);
$newDate->modify('+1 year');
echo $newDate->format('Y-m-d H:i:s');

DEMO.

Upvotes: 2

swapnesh
swapnesh

Reputation: 26732

Try this -

echo date('Y-m-d H:i:s', strtotime("+365 days"));

Upvotes: 2

Related Questions