MySQL 日期与字符串互相转换总结

第一种情况:日期转字符串

1、函数:date_format(date, format)

select date_format(now(),'%Y-%m-%d %H:%i:%S');

第二种情况:日期转时间戳

1、函数:unix_timestamp(data)

select unix_timestamp(now());
img

第三种情况:字符串转日期

1、函数:str_to_date(str,format);注:format格式必须和str的格式相同,否则返回空

select str_to_date('2020-12-20', '%Y-%m-%d %H:%i:%S');
img

第四种情况:时间戳转日期

1、函数:from_unixtime(time-stamp);

select from_unixtime(1509257408); 
img

第五种情况:时间戳转日期

1、函数:from_unixtime(time-stamp,format);

select from_unixtime(1509257408,'%Y~%m~%d %H:%i:%S');
img
posted @   哩个啷个波  阅读(4304)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示