1

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
kenan
  • 13
  • 1
  • 3

3 Answers3

1

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.

Community
  • 1
  • 1
Gordon
  • 312,688
  • 75
  • 539
  • 559
0

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
  • 1,879
  • 17
  • 18
0
//$result contain the timestamp
$lastday=strtotime('+1 year', $result);
echo date('Y-m-t H:i',$lastday);

here :)

Marcx
  • 6,806
  • 5
  • 46
  • 69