get mysql records just from today with offset
I'm trying to get all the records just for today but having trouble. Another thing I'm unsure of how to factor in is that my server time is two hours ahead of my local time so I'll need to figure out the offset. I'm off setting the time when I'm inserting the data just not sure how to do it on retrieval of if I'll need to.
mysql_query("SELECT `* FROM table WHERE DATE_SUB(开发者_如何学GoCURDATE(),INTERVAL 1 DAY) <= `date` AND `alert_status` ='0'") or die(mysql_error());
I think part of the problem is the <=
I tried just using =
and ==
but neither worked.
What exactly is the problem you're running into? What do you mean when you say that it doesn't work?
I see a syntax error (the backtick right before the asterisk), but I'm not sure what your issue is. That DATE_SUB
call looks reasonable to me.
Edit: try something like this:
WHERE `date` BETWEEN DATE_SUB(CURDATE(),INTERVAL 1 DAY) AND CURDATE()
...which is just a fancy way of doing this:
WHERE `date` >= DATE_SUB(CURDATE(),INTERVAL 1 DAY) AND `date` <= CURDATE()
精彩评论