3. mysql中常用的字符与时间函数

函数
1. 日期转字符
select date_format(now(), '%Y%m%d-%H%i%s');
select date_format(now(), '%Y%m%d-%H%i%s') from student;
select date_format(now(), '%Y%m%d') from student;
2. 获取毫秒需要在应用层想办法, 数据库存储的字段类型为char
3. 字符转日期
select str_to_date('2018-04-17', '%y-%m-%d %H');
4. 时间转时间戳
select unix_timestamp(now());
5. 字符串转时间戳
select unix_timestamp('2018-04-17');
6. 时间戳转字符串
select from_unixtime(1523894400);
7. 时间戳转字符串
select from_unixtime(1523894400, '%Y-%m')

原文地址:https://www.cnblogs.com/alisonGavin/p/8867567.html