How to Convert Seconds into Minutes and Hours using PHP
In this simple article we will show you how to convert seconds into minutes and hours using PHP. This is a simple PHP code that converts a seconds into a minuts and hourse.
HTML Code
<html>
<body>
<form method="post"action="">
<input type="text" name="time" placeholder="Enter Seconds">
<select name="convert_unit">
<option>Minutes</option>
<option>Hours</option>
</select>
<br>
<input type="submit" name="convert_seconds" value="Convert Seconds">
</form>
<p><?php echo $time; ?></p>
</body>
</html>
PHP Code
<?php
$time = '';
if(isset($_POST['convert_seconds']))
{
$time = $_POST['time'];
$unit = $_POST['convert_unit'];
if($unit == "Minutes")
{
$time = round($time / 60,4) . 'Min';
}
if($unit == "Hours")
{
$time = round($time / 60 / 60,4) . 'Hours';
}
}
?>
Leave a Reply