每天一个常用MySQL函数-from_unixtime等

场景
我们在MySQL中存储数据的时候,表中通常有代表时间属性的字段,更新时间、创建时间、支付成功时间等,通常为时间戳或者标准时间格式,可能会遇到需要格式化展示的需求,可以通过程序去控制或者通过MySQL内置函数控制。
可用函数
--格式化时间
from_unixtime(1586052661, "%Y-%m-%d %H:%i:%s")
--获取时间戳
unix_timestamp("2020-03-01")
--当前时间戳
unix_timestamp()
--当前时间
now() 或者 current_timestamp()
--当前日期
current_date()
--当前时间
current_time()
使用
select now(), CURRENT_DATE(), CURRENT_TIME(), CURRENT_TIMESTAMP(),
UNIX_TIMESTAMP(), FROM_UNIXTIME(UNIX_TIMESTAMP(),"%Y-%m-%d %H:%i:%s"),
UNIX_TIMESTAMP("2020-04-05");

相关推荐
-
PHP8种变量类型的详细讲解2025-02-22 00:32:24
-
php+apache 和 php+nginx的区别2025-02-22 00:21:27
-
PHP:与workerman结合实现定时任务2025-02-22 00:15:57
-
Nginx的Rewrite规则与实例2025-02-22 00:15:39
-
MySql中身份证字段的简单脱敏介绍2025-02-22 00:15:36