Reputation: 13
I want that items hide after the time expired, only today and future items would be shown.
I have code like that now but it doesn't work:
$result = mysql_query("SELECT * FROM table WHERE closing_date >= CURRENT_DATE()");
$numrow = mysql_num_rows($result);
In the MYSQL I have closing_date in that format:
sample: 2014-07-03 20:11:26
So now if time expire item would not be shown on page.
The code don't want work I had tryed many solutions but none didn't work :(
Timeformat must stay same as it is.
Thanks for help!
Upvotes: 0
Views: 516
Reputation: 866
CURRENTDATE() is in the format 1997-12-15. If your format is 2014-07-03 20:11:26, you could do something like this.
$currentDate = date(Y-m-d G:i:s);
$result = mysql_query("SELECT * FROM table WHERE closing_date >=" . $currentDate);
$numrow = mysql_num_rows($result);
Upvotes: 0
Reputation: 4481
CURRENT_DATE() just returns the date without time. that's why your code doesn't work as you want it to. you need to add the time, for example like this:
$result = mysql_query("SELECT * FROM table WHERE closing_date >= CONCAT(CURDATE(), ' ', CURTIME())");
$numrow = mysql_num_rows($result);
Upvotes: 1
Reputation: 7653
You need to set up cronjob
that will run once a day or every few minutes that will run a script which will hide those items.
Your script should have this query:
UPDATE table SET hide_column = 1 WHERE closing_date < CURRENT_DATE()
If you dont want to hide anything and just grab data from today & after today you need to know what is the type of your closing_date column. If its datetime
use NOW()
to compare:
SELECT * FROM table WHERE closing_date >= NOW()
Upvotes: 1