Link to home
Start Free TrialLog in
Avatar of skylabel
skylabel

asked on

Comparing datetimes and timezone issue

I have the following code to retrieve a date and compare with the present time, which works, but what if I want to say as long as it's still today, count it as the future, even though the time might have past already.

Also, I'm not too sure how to handle time zones with this, as $commenceDate, which is stored in MySQL database  and refers to a GMT +8 timezone. I'm using PHP 4.3.

$commenceDateTime = $row['commenceDateTime']; //read from MySQL datetime field
$commenceDateTime = strtotime( $commenceDateTime );

$currentDateTime = mktime();

if ($currentDateTime >= $commenceDateTime) {
   echo "past";
}

else {
   echo "future";
}
ASKER CERTIFIED SOLUTION
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial