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;
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:
Calculate months, years and days between two given dates as timestamp [duplicate]
(4 answers)
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 2 years ago.
Here is my code:
<?php
$userDob = $result['DoB'];
//Create a DateTime object using the user's date of birth.
$dob = new DateTime($userDob);
//We need to compare the user's date of birth with today's date.
$now = new DateTime();
//Calculate the time difference between the two dates.
$difference = $now->diff($dob);
//Get the difference in years, as we are looking for the user's age.
$age = $difference->y;
//Print it out.
echo $age;
?>
I want to output something like 50 Years, 6 Months, 20 Days but I don't know how to exactly put it as this method is only outputting number of years only.
Yes php has something built in for that :)
$age_check = "$day-$month-$year";
$today = date("Y-m-d");
$calculate = date_diff(date_create($age_check),date_create($today));
$age = $calculate->format('%y');
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:
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:
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