Timeconvertion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Timeconvertion

Post by tores »

Hi

How can I convert e.g 135 minutes to 02:15:00, without writing tons of code?

[edit]

Code: Select all

<?php
   $minutes = 135;
	$mins = $minutes % 60;
	$hours = ($minutes - $mins) / 60;
	$mins = sprintf("%02s", $mins);
	$hours = sprintf("%02s", $hours);
	$timestamp = $hours.":".$mins.":00";

?>
regards tores
Last edited by tores on Thu Aug 12, 2004 3:48 am, edited 1 time in total.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

<?php
$mins=135;
echo intval($mins/60).':'.($mins%60);
?>

Code: Select all

<?php
$mins=135;
echo intval($mins/60).':'.(($mins/60-intval($mins/60))*60);
Post Reply