开发者

Unix time to Date in Mysql

开发者 https://www.devze.com 2023-03-24 06:17 出处:网络
i have column visit_ti开发者_StackOverflow中文版me and fields in this column are integers (unix time).

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()
0

精彩评论

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