6、日期转换
6.1、日期、字符串互转
- date_format(date, format)日期转字符串
date_format(date, format) 函数用于以不同的格式显示日期/时间数据。
TIME_FORMAT(time,format) 时间格式化
- tr_to_date(str,format) 字符串转日期 。
select str_to_date('08/09/2008', '%m/%d/%Y');
6.1.2、(日期、天数)转换函数
- to_days(date) :将日期转换成总天数
- from_days(days) 将总天数转换成日期
select to_days('0000-00-00');
select to_days('2008-08-08');
6.1.3. (时间、秒)转换函数:
- time_to_sec(time) 将时间转换总秒数
- sec_to_time(seconds) :将总秒数转换成时间
select time_to_sec('01:00:05');
select sec_to_time(3605);
6.2 日期(字符串)转时间戳
2.1、日期时间戳互转
- unix_timestamp(date) 日期/字符串转时间戳
- rom_unixtime(unix_timestamp, format) 时间戳转日期
select unix_timestamp(now());
select from_unixtime(1451997924);
2.2、字符串时间戳互转
select unix_timestamp('2016-01-02');
select from_unixtime(1451997924,'%Y-%d');