【MySQL】日期函数:仿trunc、当年、当月、当天
生活随笔
收集整理的這篇文章主要介紹了
【MySQL】日期函数:仿trunc、当年、当月、当天
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前言
- mysql 5.7.31
思路
- 將日期格式化得到字符串
- 將字符串轉(zhuǎn)換成date類型(此步根據(jù)實(shí)際情況決定是否需要)
當(dāng)年
SELECT @year := date_format(now(), '%Y0101'); /* 將日期格式化,得到當(dāng)年字符串 */ SELECT str_to_date(@year, '%Y%m%d'); /* 將字符串轉(zhuǎn)換成date類型 */SELECT str_to_date(date_format(now(), '%Y0101'), '%Y%m%d'); /* 寫到一起 */當(dāng)月
SELECT str_to_date(date_format(now(), '%Y%m01'), '%Y%m%d');當(dāng)天
SELECT str_to_date(date_format(now(), '%Y%m%d00'), '%Y%m%d%H');參考
https://blog.csdn.net/weixin_45873444/article/details/118190796
總結(jié)
以上是生活随笔為你收集整理的【MySQL】日期函数:仿trunc、当年、当月、当天的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 百度理财产品怎么买
- 下一篇: 【MySQL】日期函数:日期、时间增减