mysql中的sql时间格式转换

from_unixtime(unix_timestamp, format)
把时间戳转化为指定的格式
as:
select from_unixtime(addTime, '%Y-%m-%d %h:%i:%s') as datetime from table1

unix_timestamp([datetime])
把日期时间转化为时间戳
as:
select from_unixtime([addDay]) as unixtime from table1

case(value as type)
convert(value, type)
都是把指定的值和类型转化了指定的类型并产生相应的值
其中类型(type)如下:
signed:整型
unsigned:无符号整型 
decimal:浮点型
datetime:日期型
time:时间
date:日期
char():字符型,可带参数
binary:二进制
as :
select cast('123abc' as signed) as res; //转为整型 
123
--------------
select convert('123.001', signed);
123
-------------
其中,convert(value using charset),可转化了指定的字符集编码
as:
select convert('要的值' using utf8) // 转为 utf8

  

原文地址:https://www.cnblogs.com/lin3615/p/4214733.html