您好,欢迎来到客趣旅游网。
搜索
您的当前位置:首页mysql查询时间戳和日期的转换_MySQL

mysql查询时间戳和日期的转换_MySQL

来源:客趣旅游网

bitsCN.com

mysql查询时间戳和日期的转换

在数据库的使用中,经常需要按指定日期来查询记录,以便于统计,而在数据库中,有很多存储的是时间戳,

也有的直接存日期,查询的时候可能不是那么好弄.

mysql提供了两个函数:

from_unixtime(time_stamp) -> 将时间戳转换为日期

unix_timestamp(date) -> 将指定的日期或者日期字符串转换为时间戳

如: from_unixtime(time_stamp)

[plain] select from_unixtime(13824000); +---------------------------+ | from_unixtime(13824000) | +---------------------------+ | 2013-10-24 00:00:00 | +---------------------------+ 如: unix_timestamp(date) [plain] select unix_timestamp(date('2013-10-24')); +------------------------------------+ | unix_timestamp(date('2013-10-24')) | +------------------------------------+ | 13824000 | +------------------------------------+ 如果要查询当天的订单的记录:[plain] select count(*) from b_order Where date_format(from_unixtime(create_time),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d') 也可以这样:[plain] select count(*) from b_order Where create_time >= unix_timestamp('2013-10-24 00:00:00') and create_time <= unix_timestamp('2013-10-24 23:59:59') ; 


bitsCN.com

Copyright © 2019- kqyc.cn 版权所有 赣ICP备2024042808号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务