MySQL学习笔记| 函数篇

1、时间函数

1、当前时间戳
curdate();#当前日期2017-08-21
curtime();# 当前时间23:47:12
now();# 当前时间戳2017-08-21 23:47:12
sysdate();# 当前时间,获取函数执行那一刻时的时间

2、时间解析
date(now());# 2017-08-21
year(now());#2017
month(now());#8
monthname(now());
week(now());#34
day(now());#21
dayname(now());#Monday
time(now());#23:47:12
hour(now());#23
minute(now());#47
second(now());#12


dayofyear(now());#233
dayofmonth(now());
dayofweek(now());
weekday(now());#0
last_day(now());
quarter(now());#季度

3、日期IO
date_format(now(),'%Y-%m-%d');
time_format(now(),' %H:%i:%s');
str_to_date('2017/08/21','%Y/%m/%d');
convert_tz(date,form_tz,to_tz);#时区

4、时间计算
adddate(now(),5);# 加5天
adddate(now(),interval 2 month);
addtime(now());
datediff(now(),adddate(now(),5));
timediff(now(),addtime(now(),60));

2、数学函数

  • 查询并插入旧表
    语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1

  • 查询插入新表
    语句形式为:SELECT vale1, value2 into Table2 from Table1
    regexp

你可能感兴趣的:(MySQL学习笔记| 函数篇)