0

I want to update a unix timestamp and add x months.

This is a timestamp that i use 1456256866

 strtotime("+1 month")

what i want to accieve is :

$time = '1456256866';
    //update $time with x months something like
$time("+5 month");

Can someone put me in the right direction?

Much Thanks

2 Answers 2

1

You could do something like below. the function strtotime takes a second argument.

$time = 1456256866;
$time = strtotime('+5 month', $time);
Sign up to request clarification or add additional context in comments.

Comments

0

For such operations You should use Datetime class, especially Add method:

$date = new DateTime('@1456256866');
$date->add(new DateInterval('P5M'));
echo $date->format('Y-m-d') . "\n";

Check more here: http://php.net/manual/pl/datetime.add.php

1 Comment

Thanks, This has solved my question. I did not know of the Datetime class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.