This question already has answers here:
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 5 years ago.
I would like to get the total number of seconds based from the given time, for example the following given data below:
$timein=04-01-2017 7:56:37 am;
$timeout=04-01-2017 5:15:17 pm;
$totalseconds= ?
PHP code demo
<?php
$time1=strtotime("04-01-2017 7:56:37 am");
$time2=strtotime("04-01-2017 5:15:17 pm");
echo $time2-$time1;
Related
This question already has answers here:
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 3 years ago.
I want to calculate the time difference in Hours, Minutes and seconds between two-time intervals.
Here is my Code
$actualLoginTime = strtotime('13:49:13.0000000');
$loginTime = strtotime('09:00:00.0000000');
$nInterval = ($actualLoginTime) - ($loginTime);
{{date("H:i:s ", strtotime($nInterval))}}
It's giving me the wrong Output and showing the difference 5:00:00.
Can you guys please help me.
I found the solution to my Question by using gmdate() function:
echo gmdate("H:i:s", $nInterval );
This question already has answers here:
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 4 years ago.
what I want to do is calculate the latein these time:
Time-in = 22:00 (10:00 PM)
Time-out = 1:30 (1:30 AM)
The output should be 3:30 i want to get this output
How can I calculate the difference and what built-in function in php should be used to achieved this? Can someone give me a clue?
Assuming your times are strings in the form HH:mm, this will work:
$in = new DateTime('22:00');
$out = new DateTime('01:30');
// if in is > out, assume out is on the next day
if ($in > $out) $out->add(new DateInterval('P1D'));
$diff = $out->diff($in);
echo $diff->format('%H:%i');
This question already has answers here:
PHP and MySQL Subtract Seconds From Time
(4 answers)
Closed 6 years ago.
I have a report I built but the problem is the subtract time in the database.
as
$intime= "02:00:00";
$outtime= "03:25:50";
Output will be 01:25:50
So my question is how can I take an action in PHP (string of mysql format time)
You can do this using PHP's DateTime class:
$a = new DateTime('02:00:00');
$b = new DateTime('03:25:50');
echo $a->diff($b)->format("%H:%I:%S"); // 01:25:50
This question already has answers here:
convert month from name to number
(17 answers)
Closed 6 years ago.
I want to enter the full name of the month and in response i want to get the number of the month.
i have tried following code, when i pass the "March" as month name it return me "1".is there any way to get the number of the month in php?
$month_number = date('n', strtotime($string));
Try this :
<?php
$date = date_parse('March');
echo($date['month']);
?>
May this will help you :)
Try:
date('m', strtotime("March"));
This question already has answers here:
Convert the time format in php
(2 answers)
Closed 7 years ago.
Can I print a current time in this format? (00:00:00:)
echo date("H:i:s","00:00:00");
output: 01:00:00
I want output: 00:00:00
Yes you can with strtotime():
echo date("H:i:s",strtotime("00:00:00"));