Getting Hour and Minute in PHP
print date('H:i');
$var = date('H:i');
Should do it, for the current time. Use a lower case h
for 12 hour clock instead of 24 hour.More date time formats listed here.
Get Hour and minute from time string
Create a DateTime object by passing that string into the constructor and just format it to your liking with format()
! You might want H:i
if you just want the hours and minutes, or H:i:s
if you want to include the seconds.
$string = "2019-05-08T10:36:00+0530";
$date = new DateTime($string);
echo $date->format("H:i:s");
- Live demo at https://3v4l.org/BmnoU
How to get time difference in minutes in PHP
Subtract the past most one from the future most one and divide by 60.
Times are done in Unix format so they're just a big number showing the number of seconds from January 1, 1970, 00:00:00 GMT
PHP Current time in Hour:Minutes
i think in this case it would be very use full to use the DateTime class from PHP. The Problem with your code is strtotime returns a int not an DateTime object.
I've modified your code so it will work:
$org = new DateTime("2018-01-07 16:35:10");
$then = $org->add(new DateInterval("PT6H"));
echo $then->format("H:i"),"<br>";
$afterThen = $then->add(new DateInterval("PT15M"));
echo $afterThen->format("H:i");
days, hours, and minutes remaining in php
Always use DateTime
$create_time = "1496592689";
$current_time = time();
$dtCurrent = DateTime::createFromFormat('U', $current_time);
$dtCreate = DateTime::createFromFormat('U', $create_time);
$diff = $dtCurrent->diff($dtCreate);
$interval = $diff->format("%y years %m months %d days %h hours %i minutes %s seconds");
$interval = preg_replace('/(^0| 0) (years|months|days|hours|minutes|seconds)/', '', $interval);
echo $interval;
result 6 months 30 days 5 hours 52 minutes
Get date, hour and minute as separate variables from a datetimestamp in PHP
The easiest way is to use PHP DateTime class
$getTimeStamp = '2013-09-26 13:06:00';
$date = new \DateTime($getTimeStamp);
$dateString = $date->format('Y-m-d');
$hourString = $date->format('H');
$minuteString = $date->format('i');
PHP: How to get current time in hour:minute:second?
Anytime you have a question about a particular function in PHP, the easiest way to get quick answers is by visiting php.net, which has great documentation on all of the language's capabilities.
Looking up a function is easy, just visit http://php.net/<function name>
and it will forward you to the appropriate place. For the date function, we'll visit http://php.net/date.
We immediately learn a couple things about this function by examining its signature:
string date ( string $format [, int $timestamp = time() ] )
First, it returns a string. That's what the first string
in the above code means. Secondly, the first parameter is expected to be a string containing the format. There is an optional second parameter for passing in your own timestamp (to construct strings from some time other than now).date("d-m-Y") // produces something like 03-12-2012
In this code, d
represents the day of the month (with a leading 0 is necessary). m
represents the month, again with a leading zero if necessary. And Y
represents the full 4-digit year. All of these are documented in the aforementioned link.To satisfy your request of getting the hours, minutes, and seconds, we need to give a quick look at the documentation to see which characters represents those particular units of time. When we do that, we find the following:
h 12-hour format of an hour with leading zeros 01 through 12
i Minutes with leading zeros 00 to 59
s Seconds, with leading zeros 00 through 59
With this in mind, we can no create a new format string:date("d-m-Y h:i:s"); // produces something like 03-12-2012 03:29:13
Hope this is helpful, and I hope you find the documentation has benefiting to your development as I have to mine. Convert seconds to Hour:Minute:Second
You can use the gmdate()
function:
echo gmdate("H:i:s", 685);
Related Topics
Automatically Cancel Order After X Days If No Payment in Woocommerce
MySQL Insert ....On Duplicate Update - Adds One to the Autoincrement
How Does PHP Max_Execution_Time Work
Why Do PHP Array Examples Leave a Trailing Comma
Possible to View PHP Code of a Website
Mail Not Sending with PHPmailer Over Ssl Using Smtp
How to Add Item to the JSON File Formatted Array
How to Resize and Convert an Uploaded Image to a Png Using Gd
Reload the Page After Ajax Success
A Better Way to Replace Emoticons in PHP
Magento Products by Categories
How to Retrieve Date from Table Cell Using PHPspreadsheet
Bool Parameter from Jquery Ajax Received as Literal String "False"/"True" in PHP
Selenium2 Firefox: Use the Default Profile