mysql 时间戳与日期格式的相互转换
2016-11-14 12:15
786 查看
(5141) (0)
1、UNIX时间戳转换为日期用函数: FROM_UNIXTIME()
[sql] view
plain copy
select FROM_UNIXTIME(1156219870);
输出:2006-08-22 12:11:10
2、日期转换为UNIX时间戳用函数:
UNIX_TIMESTAMP()
[sql] view
plain copy
Select UNIX_TIMESTAMP('2006-11-04 12:23:00');
[sql] view
plain copy
输出:1162614180
[sql] view
plain copy
Select UNIX_TIMESTAMP(NOW());
[sql] view
plain copy
[sql] view
plain copy
输出当前时间戳
例:mysql查询当天的记录数:
[sql] view
plain copy
$sql=”select * from message Where DATE_FORMAT(FROM_UNIXTIME(chattime),’%Y-%m-%d’) = DATE_FORMAT(NOW(),’%Y-%m-%d’) order by id desc”;
![](http://static.blog.csdn.net/images/save_snippets_01.png)
PHP方式转换:
UNIX时间戳转换为日期用函数:
date()
date('Y-m-d
H:i:s', 1156219870);
日期转换为UNIX时间戳用函数:strtotime()
strtotime('2010-03-24 08:15:42');
1、UNIX时间戳转换为日期用函数: FROM_UNIXTIME()
[sql] view
plain copy
select FROM_UNIXTIME(1156219870);
输出:2006-08-22 12:11:10
2、日期转换为UNIX时间戳用函数:
UNIX_TIMESTAMP()
[sql] view
plain copy
Select UNIX_TIMESTAMP('2006-11-04 12:23:00');
[sql] view
plain copy
输出:1162614180
[sql] view
plain copy
Select UNIX_TIMESTAMP(NOW());
[sql] view
plain copy
[sql] view
plain copy
输出当前时间戳
例:mysql查询当天的记录数:
[sql] view
plain copy
$sql=”select * from message Where DATE_FORMAT(FROM_UNIXTIME(chattime),’%Y-%m-%d’) = DATE_FORMAT(NOW(),’%Y-%m-%d’) order by id desc”;
![](http://static.blog.csdn.net/images/save_snippets_01.png)
PHP方式转换:
UNIX时间戳转换为日期用函数:
date()
date('Y-m-d
H:i:s', 1156219870);
日期转换为UNIX时间戳用函数:strtotime()
strtotime('2010-03-24 08:15:42');
相关文章推荐
- mysql 时间戳与日期格式的相互转换
- mysql 中日期格式 与 时间戳之间的相互转换
- mysql 时间戳与日期格式之间相互转换
- mysql 时间戳与日期格式的相互转换
- mysql 时间戳与日期格式的相互转换
- mysql 时间戳与日期格式的相互转换
- mysql 时间戳与日期格式的相互转换
- MySQL:UNIX时间戳与日期的相互转换
- mysql 时间转换 用EXCEL实现MySQL时间戳格式和日期格互转
- js时间戳和日期格式相互转换
- PHP 时间戳 与 日期的相互转换(含mysql 中直接转换)
- Java中日期时间格式与毫秒数的相互转换
- js时间戳与日期格式之间相互转换
- mysql 将时间戳直接转换成普通日期格式
- PHP+Mysql日期时间和UNIX时间戳相互转换
- MySql-时间格式转换之转换为时分秒格式的日期
- mysql获取日期(将时间戳转换成短日期格式)
- mysql 时间转换 用EXCEL实现MySQL时间戳格式和日期格互转
- js时间戳与日期格式之间的相互转换
- 时间戳和日期格式相互转换