tags:

views:

50

answers:

3

I have timestamp in DB like: 1268085720, its 2010-03-08 23:00, so its 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.

Thanks

A: 

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);
Daan
This gives 2015-09-01 on my computer when run through date(Y-m-d)
Gordon
Oups! I forgot to include the current day... xD --Edited.
Daan
@Daan Now it returns 2011-03-08. Still not what the OP was looking for. Use `date('t', $time)` instead of `date('d', $time)`
Gordon
Oh yeah, you're right. Edited again. :!
Daan
A: 
//$result contain the timestamp
$lastday=strtotime('+1 year', $result);
echo date('Y-m-t H:i',$lastday);

here :)

Marcx
"last day" is "yesterday" in strotime whereas I think the OP was last day of month
Gordon
A: 

Modification of http://stackoverflow.com/questions/1686724/php-last-day-of-the-month

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.

Gordon
This one works, thanks :)
kenan