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
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:
Convert timestamp to readable date/time PHP
(14 answers)
Closed 3 years ago.
i am using sports api and i am getting matches schedule from api but the timestamp is UTC and i want to search match according to my localdate the timestamp is look like this 1574463600
You can use # along with the unix time to create a DateTime class.
<?php
$unixTime = 1574463600;
$date = new DateTime('#' . $unixTime);
echo $date->format('d/m/Y'); // outputs 22/11/2019
See it here https://3v4l.org/eoSU9
Read about DateTime here https://www.php.net/manual/en/class.datetime
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;
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I need to reverse my date from 10/21/2016 to 2016/10/21
how can I possible to do this?
echo date('Y/m/d', strtotime('10/21/2016'));
this will helps you
use DateTime class
$date = new DateTime('10/21/2016');
echo $date->format('Y/m/d');
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
Well, I am working with twitch's API currently and I want to echo the time that the current stream started at. Currently the following is output: 2015-04-11T07:45:20Z seconds so I am wondering how I would convert this into a readable time. i.e. 07:45:20.
DateTime::createFromFormat() allows you to read in non-standard date input and turn it into a DateTime object that you can then use to format your output however you like:
$date = DateTime::createFromFormat('Y-m-d\TH:i:s\Z *', '2015-04-11T07:45:20Z seconds');
echo $date->format('H:i:s'); // 07:45:20
Demo