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. You may also like How to Currency Converter using PHP and Google API and How to convert bytes Into KB, MB and GB using PHP.


        <form method="post"action="">
            <input type="text" name="time" placeholder="Enter Seconds">
            <select name="convert_unit">
            <input type="submit" name="convert_seconds" value="Convert Seconds">
        <p><?php echo $time; ?></p>

PHP Code

$time = '';
    $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

Your email address will not be published. Required fields are marked *