-5

What is the best way to convert this time period to seconds in php? "7 days, 18:50:19" ~> "67000"

snn1024a
  • 1
  • 2

2 Answers2

1

strtotime can parse a "period" format like that natively, the only key point is to also pass in 0 as the second parameter so that the result is relative to the unix epoch rather than the current time:

$seconds = strtotime('7 days 18:50:19', 0);
echo $seconds;

672619

iainn
  • 16,826
  • 9
  • 33
  • 40
-1

Can we do better then this?

$interval = "7 days, 18:50:19";
$interval = preg_replace("/[a-z A-Z]/", "", $interval);
$int = preg_split( "/(,|:)/", $interval);
$inter = ($int[0]*86400) + ($int[1]*3600) + ($int[2]*60) + ($int[3]);
var_dump($inter);
snn1024a
  • 1
  • 2