1、UNIX时间戳转换为日期用函数: FROM_UNIXTIME()
select FROM_UNIXTIME(1156219870); //输出:2006-08-22 12:11:10
2、日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP()
Select UNIX_TIMESTAMP('2006-11-04 12:23:00'); //输出:1162614180
例子:
查询当天的订单数 (不建议这样写法,只为了举例使用)
select count(*) from bs_order where date_format(from_unixtime(create_time),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
也可以这样写:
select count(*) from bs_order where create_time >= unix_timestamp('2013-10-24 00:00:00') and create_time < unix_timestamp('2013-10-25 00:00:00')