I know this is obvious, but my date time row is in TEXT type, and i can't figure out how to fetch records that are:
Inserted since a date until the present
-- OR --
Inserted in a specific day
Some of the failed attempts:
SELECT * FROM posts WHERE DATE(date)=DATE(NOW()) // To get today's posts
SELECT * FROM posts WHERE date>=CURDATE() // Still doesn't work.
P.S. The date row is in a DateTime
format but in a TEXT
type.
T开发者_如何学运维hanks
The function to parse strings into dates is STR_TO_DATE():
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date
It assumes that the format is fixed and known. I don't know if that's the case.
Use convert -- http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html
SELECT * FROM posts WHERE convert(date, datetime) >= CURDATE()
精彩评论