kenan
kenan

Reputation: 13

Time stamp and adding 1 year and last day in month

I have timestamp in DB like: 1268085720, it's 2010-03-08 23:00, so it's today.

How can I add one year, and to be the last day in the same month, and need to convert it like: YYYY-MM-DD HH: MM?

For given example I need 2011-03-31 23:59.

Upvotes: 1

Views: 2805

Answers (3)

Marcx
Marcx

Reputation: 6836

//$result contain the timestamp
$lastday=strtotime('+1 year', $result);
echo date('Y-m-t H:i',$lastday);

here :)

Upvotes: 0

Daan
Daan

Reputation: 1879

Use mktime();

$time=1268085720;
$nextyear=mktime(date('h', $time), date('i', $time), date('s', $time), date('m', $time), date('t', $time), date('Y', $time)+1);

Upvotes: 0

Gordon
Gordon

Reputation: 317119

Modification of How to find the last day of the month from date?

echo date("Y-m-t 23:59:59", strtotime("+1 year", 1268085720));
// -> 2011-03-31 23:59:59

The t format gives the number of days in the given month (28 through 31). If you want the real hours and minutes, use Y-m-t H:i:s instead of the hardcoded time.

Upvotes: 1

Related Questions