MySQL 内置函数之时间函数
MySQL 大约 642 字时间函数
- 获取子值,语法如下
year(date)
返回date
的年份(范围在1000
到9999
)month(date)
返回date
中的月份数值day(date)
返回date
中的日期数值hour(time)
返回time
的小时数(范围是0
到23
)minute(time)
返回time
的分钟数(范围是0
到59
)second(time)
返回time
的秒数(范围是0
到59
)
select year('2016-12-21');
- 日期计算,使用
+-
运算符,数字后面的关键字为year
、month
、day
、hour
、minute
、second
select '2016-12-21'+interval 1 day;
- 日期格式化
date_format(date,format)
,format
参数可用的值如下- 获取年
%Y
,返回4
位的整数 - 获取年
%y
,返回2
位的整数 - 获取月
%m
,值为1-12
的整数 - 获取日
%d
,返回整数 - 获取时
%H
,值为0-23
的整数 - 获取时
%h
,值为1-12
的整数 - 获取分
%i
,值为0-59
的整数 - 获取秒
%s
,值为0-59
的整数
- 获取年
select date_format('2016-12-21','%Y %m %d');
- 当前日期
current_date()
select current_date();
- 当前时间
current_time()
select current_time();
- 当前日期时间
now()
select now();
阅读 1903 · 发布于 2019-04-07
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Arthas 监控安装成 Windows 服务的 Tomcat阅读 2415
-
Linux -bash: locate: command not found阅读 998
-
Linux grep 抓取多个关键字阅读 2620
-
Alpine Linux 安装 chattr阅读 1149
-
skaffold init 提示 one or more valid Kubernetes manifests are required to run skaffold阅读 933
-
Windows 命令行中打开文件夹阅读 1668
-
使用 LuaRocks 管理 Lua 依赖阅读 3803
-
Java jar 包启动时指定 JVM 时区阅读 5811
-
Kubernetes kubectl logs -f 过滤关键日志阅读 1294
-
前端 Chrome 反《反调试》阅读 12416