I am struggling very hard to achieve this but the results are not what i am trying to get.The result values are wrong and the colons are not on their proper place when using random minute values(that should generate years : months : weeks : days : hours : minutes) from such as 1500, 2800 .etc
I want to convert Minutes into respective years : months : weeks : days : hours : minutes
What i have tried?
$minutesConverter = function($from,$to,$format='dynamic'){
$year = floor($from/525600) ? floor($from/525600) : '';
$Rminutes= $from%525600;
$month = floor($Rminutes/43800.048) ? floor($Rminutes/43800.048) : '';
$Rminutes= $from%43800.048;
$week = floor($Rminutes/10080) ? floor($Rminutes/10080) : '';
$Rminutes= $from%10080;
$day = floor($Rminutes/1440) ? floor($Rminutes/1440) : '';
$Rminutes= $from%1440;
$hour = floor($Rminutes/60) ? floor($Rminutes/60) : '';
$minute = $from%60 ? $from%60 : '';
if(!empty($year) ){ if($year > 1 ){ $year = $year.' years'; }else{ $year = $year.' year'; } }
if(!empty($month) ){ if($month > 1 ){ $month = $month.' months'; }else{ $month = $month.' month'; } }
if(!empty($week) ){ if($week > 1 ){ $week = $week.' weeks'; }else{ $week = $week.' week'; } }
if(!empty($day) ){ if($day > 1 ){ $day = $day.' days'; }else{ $day = $day.' day'; } }
if(!empty($hour) ){ if($hour > 1 ){ $hour = $hour.' hours'; }else{ $hour = $hour.' hour'; } }
if(!empty($minute)){ if($minute > 1 ){ $minute = $minute.' minutes'; }else{ $minute = $minute.' minute'; } }
if(!empty($year)) { $year = $year; }
if(!empty($month)) { if(empty($year)){ $month = $month; }else{ $month = ' : '.$month; } }
if(!empty($week)) { if(empty($month)){ $week = $week; }else{ $week = ' : '.$week; } }
if(!empty($day)) { if(empty($week)){ $day = $day; }else{ $day = ' : '.$day; } }
if(!empty($hour)) { if(empty($day)){ $hour = $hour; }else{ $hour = ' : '.$hour; } }
if(!empty($minute)) { if(empty($hour)){ $minute = $minute; }else{ $minute = ' : '.$minute; } }
return $year.$month.$week.$day.$hour.$minute;
};
Example:
For using minute value as 131400 i,e 3 Months(according to google calculator) But the output of this is:
2 months6 hours
Problems?
No colons
Wrong Readable time
Help Needed ! Kindly take a look.