入職第三天,mysql資料庫,有些手生,整理下常用日期函式
-- 1.當前日期
select curdate() from dual; -- 2017-07-19
select current_date() from dual; -- 2017-07-19
-- 2.當前時間(年月日 時分秒級別)
select current_timestamp() from dual; -- 2017-07-19 17:13:25
select now() from dual; -- 2017-07-19 17:47:29
-- 3.當前時間(僅時分秒)
select current_time() from dual; -- 17:12:46
-- 4.當前年份
select year(curdate()) from dual; -- 2017
-- 5.所在月份
select month(curdate()) from dual; -- 7
-- 6.當前日
select day(curdate()) from dual; -- 19
-- 7.當前月的第一天
select date_add(curdate(), interval - day(curdate()) + 1 day); -- 2017-07-01
-- 8.當前月的最後一天
select last_day(curdate()) from dual; -- 2017-07-31
-- 9.當前季度
select quarter(curdate()) from dual; -- 3
-- 10.1天後 1月後 1年後
select adddate(curdate(),interval 1 day) from dual; -- 2017-07-20
select adddate(curdate(),interval 1 month) from dual; -- 2017-08-19
select adddate(curdate(),interval 1 year) from dual; -- 2018-07-19
mysql 日期常用函式
mysql 中最重要的內建日期函式 函式描述 now 返回當前的日期和時間 curdate 返回當前的日期 curtime 返回當前的時間 date 提取日期或日期 時間表示式的日期部分 extract 返回日期 時間按的單獨部分 date add 給日期新增指定的時間間隔 date sub 從日期...
mysql 常用的日期函式
在做統計時避免不了計算時間,今天小菜簡單分享點mysql中常用的計算時間的函式,自己會寫點簡單的例子,如果有什麼問題歡迎指出。提取時間中的各個部分 1 提取日期部分 date expr 2 提取時間部分 time expr 3 提取指定值 如 時 分 秒 年 月 日 方法一extract unit ...
MySql常用日期函式案例
會員表,t member id 主鍵,redtime 註冊日期,curdate 獲取當前的日期 檢視今天新增會員數 select count from t member where regtime curdate weekday 獲取當前日期為當前周的第幾天 0 星期一,6 星期天 subdate ...