mysql的时间戳函数from_unixtime函数

2022/8/31 2:25:11

本文主要是介绍mysql的时间戳函数from_unixtime函数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

参考:https://www.cnblogs.com/lsz-lsc/p/12802015.html

时间戳转为时间:

from_unixtime( unixtime,format),其中unixtime必须为整型(bigint),d若时间为秒时是10位,时间为毫秒时为13位。format是字符型(string),为所要转换的日期

例:from_unixtime(cast(substr(dt,1,10)as bigint),"yyyy-MM-dd")as time

dt 原为string类型,使用substr函数取 dt 的前10位,再使用cast函数转换成bigint类型,最后转为日期,精准到日。
CAST函数用于将值从一种数据类型转换为表达式中指定的另一种数据类型

如果dt是bigint类型的可以将dt/1000。
例如:
select FROM_UNIXTIME(create_date/1000,'%Y') as year,FROM_UNIXTIME(create_date/1000,'%m') as month,count(*) as count from ms_article group by year,month



这篇关于mysql的时间戳函数from_unixtime函数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程