mysql UNIX时间戳与日期的相互转换
UNIX时间戳转换为日期用函数: FROM_UNIXTIME()
1select FROM_UNIXTIME(1156219870);
日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP()
1Select UNIX_TIMESTAMP(’2006-11-04 12:23:00′);
例:mysql查询当天的记录数:
1$sql=”select * from message Where DATE_FORMAT(FROM_UNIXTIME(chattime),’%Y-%m-%d’) = DATE_FORMAT(NOW(),’%Y-%m-%d’) order by id desc”;
当然大家也可以选择在PHP中进行转换
UNIX时间戳转换为日期用函数: date()
1date('Y-m-d H:i:s', 1156219870);
日期转换为UNIX时间戳用函数:strtotime()
1strtotime('2010-03-24 08:15:42');
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/unixtime-mysql/5401.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.