MySQL 内置函数之时间函数
MySQL About 642 words时间函数
- 获取子值,语法如下
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();
Views: 2,908 · Posted: 2019-04-07
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...