开发者

Returning rows on a certain date in MySQL

I've looked through past questions - but couldn't find开发者_JAVA百科 a good match. How do I return all MySQL rows where the column timestamp is on day X, where day X is contained in a PHP variable the following format: "13 Apr 2011", and the timestamp is in database is in the following format: "2011-02-25 22:00:17"?

SELECT * WHERE timestamp (need to add here)

Thanks!


If the date string (in your PHP variable) has a consistent format, you can use the MySQL function str_to_date to convert it into a DATETIME suitable for comparison.


SELECT * FROM tablename WHERE DATE_FORMAT(timestamp,'%e %b %Y') = 'date coming from php'

(It's the opposite of andri's suggestion, it converts the timestamp into a string for comparision)


What you need is STR_TO_DATE

SELECT * WHERE DATE(`timestamp`) = STR_TO_DATE('$var','%M %d %Y') 

More here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜