I have logical problem with if...else
in PHP that using date in operation.
What I want is:
- if
$jd
less than$jam
printout 'red' - if between
$jam
and$jam
plus 2 hours printout 'green', - if
$jd
more than$h1
printout 'white'.
This is the source code:
date_default_timezone_set('Asia/Jakarta');
$jam = Date('H:i');
$jd = '12:00:00';
$h1 = $jd + 2;
if ($jd > $h1){
echo 'white';
} elseif ($jd < $h1) {
if ($jd > $jam) {
echo 'green';
} else {
echo 'red';
}
}
The problem is the $jd
value more than $jam
plus 2 hours it's printout 'green' instead 'white'.
It seems doesn't work with date operation, but with number it's working.
My Answer:
< $jam) {
echo 'red';
} elseif ($jd >= $jam && $jd <= date('H:i', strtotime($jam . ' +2 hours'))) {
echo 'green';
} elseif ($jd > $h1) {
echo 'white';
}
Rate this post
4 of 5 based on 4829 votesComments