user3212302
user3212302

Reputation: 23

Converting a DateInterval to variable integer in php

For Example:

echo $interval->format('%h.%i Hours');

I want to store it in integer. How do i do it ?

Thanks.

Upvotes: 0

Views: 766

Answers (2)

robbmj
robbmj

Reputation: 16526

You could do this

$interval = new DateInterval('P2Y4DT6H8M');
$str = $interval->format('%d:%h:%i:%s');
list($days, $hours, $minutes, $seconds) = explode(':', $str);
$elapsedSeconds =  ($days*86400) + ($hours*3600) + ($minutes*60) + $seconds;
echo $elapsedSeconds;

Upvotes: 2

Sardor Dushamov
Sardor Dushamov

Reputation: 1667

Use strtotime :

echo strtotime('2012-03-27 18:47:00'); //--> which results to 1332866820

Upvotes: 0

Related Questions