nshah
nshah

Reputation: 597

Time Comparison Not Working PHP

I am getting a time from mysql in the format of: hh:mm:ss I need to compare it to the current time and it is not working

$result = mysql_query('SELECT * FROM events WHERE clubID = "'.$clubID.'" ORDER BY date ASC, TIME(startTime) ASC');

while ($row = mysql_fetch_assoc($result)) {

    $originaltime = $row['endTime'];
    $time = new DateTime($originaltime);

    if($time < time())
        mysql_query('UPDATE events SET passed="1" WHERE eventID = "'.$row['eventID'].'"');

}

i want the if statement to happen if the current time is already past the $time (from mysql)

Upvotes: 0

Views: 83

Answers (1)

Dmitry
Dmitry

Reputation: 591

Try to convert

new DateTime($originaltime)

to int (to seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)), so solution should be:

if ($time->format('U') < time())

Upvotes: 3

Related Questions