i have column visit_ti开发者_StackOverflow中文版me
and fields in this column are integers (unix time).
I am trying to make something like this: SELECT * FROM visits WHERE DATE(visit_time) = CURDATE()
, but it isn't working...
How to make this code work?
SELECT * FROM visits WHERE FROM_UNIXTIME(visit_time, '%Y-%m-%d') = CURDATE()
As an alternative to the other solutions presented here, you could determine the current unix time in MySQL. This might be faster for large data sets:
SELECT * FROM visits WHERE visit_time = UNIX_TIMESTAMP(NOW())
SELECT * FROM `visits` WHERE DATE(FROM_UNIXTIME(`visit_time`)) = CURDATE()
See FROM_UNIXTIME(), CURDATE() and DATE()
SELECT * FROM visits WHERE DATE(FROM_UNIXTIME(visit_time)) = CURDATE()
MySQL Manual :: Date and Time Functions
You need to use FROM_UNIXTIME for this:
SELECT * FROM visits WHERE DATE(FROM_UNIXTIME(visit_time)) = CURDATE()
精彩评论