Gulshan Gulshan -4 years ago 106
PHP Question

Php multiply price with total hours

I have to multiple total no of hours (like 13:15) with price like(500).

Example:

$hours=13:15;
$price=500;
$result=$hours*$price;
$result=???


How can i multiple total no of hours with price to get final price??

Answer Source

Something like this:

<?php
    $hours='13:15';

    list($h, $m) = explode(':',$hours);  //Split up string into hours/minutes
    $decimal = $m/60;  //get minutes as decimal
    $hoursAsDecimal = $h+$decimal;


    $price=500;
    $result=$hoursAsDecimal*$price;

?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download