0

I wonder if there is a function in php or codeigniter which can do this :

function transformTime($min)
{
    $min=(int)$min;
    $heure=(int)($min/60);
    $minute=(($min/60)-$heure)*60;


    return $heure .':' . $minute . ':00'; 
}

I want convert x minutes to a time format.

Choubidou
  • 351
  • 2
  • 4
  • 17

2 Answers2

1

Do something like this

<?php

function transformTime($min)
{
$ctime = DateTime::createFromFormat('i', $min);
$ntime= $ctime->format('H:i:s');
return $ntime;
}

echo transformTime(60); // "Prints" 01:00:00
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
1

You are almost there, just format the output with sprintf() or str_pad():

function transformTime($min)
{
    $hour = floor($min / 60);
    $min -= $hour * 60;
    return sprintf('%02d:%02d:00', $hour, $min);
}
Glavić
  • 42,781
  • 13
  • 77
  • 107