php greater than certain time
Should do it
if (((int) date('H', $currentTime)) >= 16) {
// .. do something
}
Because PHP is weak-typed you can omit the (int)
-casting.
As a sidenote: If you name a variable $currentTime
, you shouldn't add 1 hour to it, because then its not the current time anymore, but a time one hour in the future ;) At all
if (date('H') >= 16) { /* .. */ }
PHP date time greater than today
You are not comparing dates. You are comparing strings. In the world of string comparisons, 09/17/2015
> 01/02/2016
because 09
> 01
. You need to either put your date in a comparable string format or compare DateTime
objects which are comparable.
<?php
$date_now = date("Y-m-d"); // this format is string comparable
if ($date_now > '2016-01-02') {
echo 'greater than';
}else{
echo 'Less than';
}
Demo
Or
<?php
$date_now = new DateTime();
$date2 = new DateTime("01/02/2016");
if ($date_now > $date2) {
echo 'greater than';
}else{
echo 'Less than';
}
Demo
Check if date() is greater than a specific time
When you compare times and dates you can either use datetime or strtotime.
Using strings will not work as expected in all cases.
In comments you mentioned how you want to compare, and you need to add the 60 seconds to the "date", not the time().
if(strtotime($date) + 60 < time()) {
time greater than another time
DateTime objects are comparable so no need to compare their formatted strings. Just compare the objects themselves.
$CURRENTTIME = new DateTime($data['current_time']);
$OFFICETIME = new DateTime('10:20:00');
if ($CURRENTTIME > $OFFICETIME) {
echo 'you are late tody';
} else {
echo 'Thank you for being on time';
}
See this answer for how to see if a time is between two times. It's pretty much the same concept.
Sidenote: There was a typo in your code. $CURRENTTIM
which should read as $CURRENTTIME
.
PHP Check Whether Current Time Greater Than 11:00
if(date("G") >= 11) // or >10
{
// current time is greater than 11:00 AM
}
Where G
parameter for date
function stands for
24-hour format of an hour without leading zeros
Manual
How to compare if the difference of 2 times is greater than 2 hours
To compare date/time differences as simple as your example, I'd suggest to not use the DateTime() class, but use simple timestamps.
E.g.:
$transport = strtotime($row->transportDate); // strtotime parses the time if it is not a timestamp, if it already is just use as is, i.e. without strtotime()
$max = strtotime(max($forecast_array));
$intervall = abs($max - $transport);
// $intervall is now the difference in seconds therefore you can do this simple check:
if($interval >= 2 * 60 * 60){ // 2 hours à 60 minutes à 60 seconds
// interval > 2 hours
} else {
//...
}
Related Topics
Remove Everything Except Letters from PHP String
PHP String Comparasion to 0 Integer Returns True
How to Use Facebook Graph API to Retrieve Fan Photos Uploaded to Wall of Fan Page
Pdo's Rowcount() Not Working on PHP 5.2.6+
Including PHP Variables in an External Js File
Setting $_Session Doesn't Work on Localhost Using Xampp
PHP Associative Array Key Order (Not Sort)
Can Mongodb and Its Drivers Preserve the Ordering of Document Elements
Set Multiple='False' in a Form in a Many to Many Relation Symfony2
Strip_Tags() Function Blacklist Rather Than Whitelist
How to Access the Google Spreadsheets API in PHP
Check If Username Exists in MySQL Table via PHP
Attach Image to Facebook Event (PHP Sdk, Rest or Graph API)
Why Is My Database Backup Script Not Working in PHP
PHP Type Hinting Not Getting Along with Interfaces and Abstract Classes
How to JSON_Encode PHP Array But the Keys Without Quotes
JavaScript or Jquery Doesn't Work in Dynamically Generated Content