Reputation: 147
Forgive me if this is a simple question, but I am trying to echo out rows that are only in the future, ie: greater than today's date and time. This is my code so far:
$date = date('Y-m-d');
$time = date("G:i:s", time());
$eventsquery = "SELECT * FROM events as A WHERE tech='$userecho' AND date >= '$date' ORDER BY date ASC, time ASC";
$eventsresult = mysql_query($eventsquery, $eventsdbhandle);
This works great for giving me rows that are either for today or in the future, This problem is, this will give me entries that happened before the current time on the current day. So I tried adding this:
$eventsquery = "SELECT * FROM events as A WHERE tech='$userecho' AND date >= '$date' AND time >= '$time' ORDER BY date ASC, time ASC";
But I get no rows at all. I know this is likely an easy fix, but I have found nothing on this site that fixes it. Any help would be great.
Time in the table is stored in this format: hh:mm:ss ie: 14:23:12
Upvotes: 1
Views: 1855
Reputation: 1704
If you have 1 column of datetime value you can say
"SELECT * FROM table_name WHERE entry_time > NOW()"
However, it gets complicated if you have two different columns for date and time each You will have to use
"SELECT * FROM table_name WHERE entry_date > CURDATE() OR (entry_date = CURDATE() AND entry_time > CURTIME()"
Upvotes: 3