PHP Greater Than Certain Time

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



Leave a reply



Submit