Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time string to total minutes integer in PHP

Tags:

php

Simple question, but can't find it elsewhere:

How can I transform my string of time e.g. "09:30" into in integer containing the total minutes in that time? (Solution for "09:30" would be 570)

I have tried a lot of stuff, including substr, mktime and strtottime and just can't get it to work.

like image 941
Pangolin Avatar asked Sep 15 '11 11:09

Pangolin


2 Answers

$time = explode(":","09:30");
$minutes = intval($time[0])*60 + intval($time[1]);
like image 123
OZ_ Avatar answered Oct 10 '22 09:10

OZ_


Just for reference, strtotime works as well and it may be a simpler solution.

$minutes = strtotime('09:30', 0) / 60;
like image 33
Ernesto Allely Avatar answered Oct 10 '22 09:10

Ernesto Allely