fmask
fmask

Reputation: 481

calculate date from seconds in php

Calculating future date from seconds.

$var = 5183990; //seconds
$today = '2013-02-16 11:00:00'; //date

like I have 5183990 seconds as a variable $var.
Now I want to know future date/time after 5183990 seconds from current time.

Upvotes: 0

Views: 3084

Answers (3)

Sherin Jose
Sherin Jose

Reputation: 2526

You can use,

echo date("Y m d h:i:s a",time()+$var);

where,

time() returns the current time then add the seconds in $var it will produce the time after $var seconds....the date() then formats that to your choice...

Upvotes: 1

Naveen D Almeida
Naveen D Almeida

Reputation: 877

Try this

strtotime('2013-02-16 11:00:00')-time()+$var;

details : http://php.net/manual/en/function.strtotime.php

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324600

Since time() returns the current timestamp in seconds, just add your interval in seconds to it, then format it as a date:

echo date("Y-m-d H:i:s",time()+$var);

Upvotes: 4

Related Questions