user816604
user816604

Reputation:

How to add months to timestamp

I have a timestamp $timestamp. How do I add 6 months to that timestamp using strtotime?

I was thinking of doing

$date = date('Y-m-d H:i:s', $timestamp);
$sixmonths_fromnow = strtotime('+6 months', $date);

but can I use strtotime directly on the timestamp? do I have to use the date() function first?

Upvotes: 2

Views: 5386

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78994

You need to use the timestamp:

$sixmonths_fromnow = strtotime('+6 months', $timestamp);
echo date('Y-m-d H:i:s', $sixmonths_fromnow);

Upvotes: 5

Related Questions