Al Hennessey
Al Hennessey

Reputation: 2445

Working out the future date with minutes variable

say i have a variable integer of 3000

Which equates to 3000 minutes, how would i work out the date from now, to 3000 minutes into the future?

If it helps, i do have some php which has already broken it down into the variables

$days
$hours
$minutes

Thanks for the help

Upvotes: 1

Views: 87

Answers (3)

Marc B
Marc B

Reputation: 360602

Assuming PHP >= 5.2.0:

$d = new DateTime();
$future = $d->add(new DateInterval("PT{$minutes}i"));
                                               ^-- i/m(i)nutes, h/hour, d/day
echo $future->format('c');

Upvotes: 2

Herbert
Herbert

Reputation: 5778

The simplest way I can think of is:

$minutes = 3000;

$newDate = new DateTime("now + {$minutes} minutes");
echo $newDate->format('m/d/Y H:i:s')

Upvotes: 2

Explosion Pills
Explosion Pills

Reputation: 191729

strtotime('+3000 minutes') will give you the timestamp 3000 minutes in the future. You can use that timestamp to format with dates.

Alternatively, you can use the DateTime class to do the addition with the add method, but I think it that's a bit more verbose than what you need.

Upvotes: 1

Related Questions