This question already has answers here:
Convert time in HH:MM:SS format to seconds only?
(10 answers)
Closed 3 years ago.
Person a has an hourly rate of 9.500 (Yes three decimal places in our country)
He has worked for 8 hours and 15 minutes and 0 seconds which is in the format 08:15:00.
Im getting the variables as below
$iCostPerHour = '9.500';
$timespent = '08.15'; //i got this by converting from 08:15:00
How do i calculate the cost for this time?
Currently what i did is
echo number_format(($timespent * $iCostPerHour), 3, '.', ',')
And it is returing a wrong value.
What am i doing wrong here?
$iCostPerHour = 9.500;
$timespent = '08:15:00';
$timeparts=explode(':',$timespent);
$pay=$timeparts[0]*$iCostPerHour+$timeparts[1]/60*$iCostPerHour;
echo $pay;
Live demo https://eval.in/740789
Related
This question already has answers here:
function for converting time to number of seconds
(7 answers)
Convert time in HH:MM:SS format to seconds only?
(10 answers)
How to convert time from hh:mm:ss.mmm to seconds and milliseconds mysql
(1 answer)
Closed 7 months ago.
I have a time of H:i:s like 01:51:36 in my SQL table, how can we convert it to like the sum of time in seconds 01:51:36 = 110160 Seconds
My code:
SELECT * FROM tbl WHERE name = Time
while ($row = mysqli_fetch_array($result)) {
$Duration = date("%s seconds');", strtotime($row["audio_duration"]));
echo $Duration;
}
Results = %31 31UTC2022-08-08T00:02:31+00:00202280831');
This question already has answers here:
How to get time difference in minutes in PHP
(21 answers)
Closed 3 years ago.
I want to calculate total working hours of an employee for a month.The time for one session of an employee is stored in the format 'H:i:s' as as string in the database.How do I add these individual sessions to calculate total time.
The function strtotime(datetime_today) will parse to seconds relative to the difference between the current datetime and 01/01/1970
<?php
$datetime_ref_today = '0:00:00';
$ar_times[]='00:00:10';
$ar_times[]='00:01:30';
$ar_times[]='13:50:30';
$total_time = 0;
foreach($ar_times as $val)
{
$total_time += strtotime($val)-strtotime($datetime_ref_today);
echo "<br/>cumul. total_time : ".$total_time." sec";;
}
echo "<br/><br/>total_time : ".$total_time." sec";
echo "<br/>Formated total_time (H:i:s): ".gmdate("H:i:s", $total_time);
?>
This question already has answers here:
Using DateTime::diff() to return days between two dates
(2 answers)
Closed 4 years ago.
I calculate the difference of to queried dates. When the difference is lower than one month everything is correct. Here a example of a wrong result:
Query output:
$row['start'] = '2018-08-06';
$row['end'] = '2018-09-26';
Code:
$start = new DateTime($row['start']);
$end = new DateTime($row['end']);
$days = $start->diff($end)->format("%d");
Output:
$days = 20;
The DateTime difference is correct and the error only comes in when you are formatting the output. %d is the day of the month, not the total days in the DateInterval. These two datetimes are 1 month and 20 days apart. So %d only shows the 20 days part. %a should get you the total number of days.
A full guide to the format can be found here:
http://php.net/manual/en/dateinterval.format.php
This question already has answers here:
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 4 years ago.
i have two time like total worked time and total duty time. eg.
$dutyTime= 182:00:00; ("H:i:s")
$workedTime= 178:10:28; ("H:i:s")
my question is that how can i get difference between this two time;
Expected Output
$duration=03:49:32; ("H:i:s")
i tried strtotime() but i takes upto 24hrs.
<?php
$start = date_create('21:21:05'); //start time
$end = date_create('10:20:00'); // end time
$diff = date_diff( $start, $end );
$date= $diff->h.':'.$diff->i.':'.$diff->s;
echo date("H:i:s",strtotime($date));
?>
This question already has answers here:
Get interval seconds between two datetime in PHP?
(8 answers)
Closed 4 years ago.
I have to 2 dates values in PHP,
start_date_time = "2018-03-15T20:39:06Z"
end_date_time = "2018-03-17T12:42:08Z"
duration = ? // in seconds
I actually want to get total time in seconds. Please help
$start_date_time = strtotime('2011-05-12 18:20:20');
$end_date_time = strtotime('2011-05-13 18:20:20');
$durationeInSeconds = $start_date_time - $end_date_time;