在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
MySQL中日期型单行函数:
SELECT CURDATE() FROM DUAL; SELECT CURRENT_DATE() FROM DUAL; -----------------------------------(分割线)------------------------------------
SELECT CURTIME() FROM DUAL; SELECT CURRENT_TIME() FROM DUAL; -----------------------------------(分割线)------------------------------------
SELECT NOW() FROM DUAL; SELECT LOCALTIME() FROM DUAL; -----------------------------------(分割线)------------------------------------
SELECT YEAR(CURDATE()), MONTH(CURDATE()),DAY(CURDATE()) FROM DUAL; SELECT HOUR(CURTIME()),MINUTE(NOW()),SECOND(NOW()) FROM DUAL; 备注:这里的函数,其括号里面的内容来自于前面指出的几个函数。 -----------------------------------(分割线)------------------------------------
SELECT WEEK(NOW()) FROM DUAL; SELECT WEEKOFYEAR(CURDATE()) FROM DUAL; -----------------------------------(分割线)------------------------------------
SELECT DAYOFWEEK(NOW()) FROM DUAL; 代码编译结果如下: 说明当下是周四 -----------------------------------(分割线)------------------------------------
SELECT WEEKDAY(NOW()) FROM DUAL; 代码编译结果如下: 说明当下是周四 -----------------------------------(分割线)------------------------------------ 8. SELECT DAYNAME(CURDATE()),DAYNAME('2020-09-06') #隐式转换 FROM DUAL; 代码编译结果如下: 备注: 字符串转换为日期(解析)(显式转换) SELECT STR_TO_DATE('09/01/2009','%m/%d/%Y') FROM DUAL; 代码编译结果如下: 字符串转换为日期(解析)(显式转换) SELECT STR_TO_DATE('20140422154706','%Y%m%d%H%i%s') FROM DUAL; 代码编译结果如下: 字符串转换为日期(解析)(显式转换) SELECT STR_TO_DATE('2014-04-22 15:47:06','%Y-%m-%d %H:%i:%s') FROM DUAL; 代码编译结果如下: -----------------------------------(分割线)------------------------------------ 9. SELECT MONTHNAME(NOW()) FROM DUAL; -----------------------------------(分割线)------------------------------------
SELECT DATEDIFF('2021-03-06','2021-06-09') FROM DUAL; 备注:返回的值是两个日期之间所差的天数=date1-date2,若date1在date2的前面,则所得为负值。 SELECT TIMEDIFF('2019-06-06 18:23:06','2019-08-06 10:36:45') FROM DUAL; 备注:返回的值是两个时间之间所差的【小时数:分钟数:秒数】=time1-time2,若time1在time2的前面,则所得为负值。 以上就是MySQL中日期型单行函数的详细内容,更多关于mysql单行函数的资料请关注极客世界其它相关文章! |
请发表评论