1.當前時間,精確到時分秒
2.當前日期,精確到日(年月日)now
()
3.當前年份curdate
()
4.當前月year
(now()
)
5.年月日month
(日期字段)
6.年月日from_unixtime
(日期字段,
'%y'
) 年 from_unixtime
(日期字段,
'%m'
) 月 from_unixtime
(日期字段,
'%y-%m-%d'
) 年月日
7.最近時間date_format
(日期字段,
'%y%m%d'
) 年月日
8.十分鐘之內的資料max
(日期字段)
9.查詢日期所在季節日期字段》=
date_sub
(now()
,interval 10 minute)
weekday() 函式和 dayofweek() ,date_format(curdate(),』%w』)類似,concat
(floor((
date_format
(日期字段,
'%m')+
2)/3
)) sale
都是返回「某天」在一周中的位置。
不同點在於參考的標準,
weekday:(0 = monday, 1 = tuesday, …, 6 = sunday);
dayofweek:(1 = sunday, 2 = monday, …, 7 = saturday)
%w 是以數字的形式來表示週中的天數( 0 = sunday, 1=monday, . . ., 6=saturday),
0為週日,6為週六,跟我們一般的認知,一周是從周一開始的並不一樣。
10.獲取當前日期在本週的周一
方法一:
方法二:select subdate
(now()
,weekday
(now()
));
11.獲取當前日期在本週的週日(如果今天是週日獲取的將是下週周一,一般適用於國外)
select subdate
(curdate()
,date_format
(curdate()
,'%w')-
1)所以要進行判斷處理
select subdate
(curdate()
,if(date_format
(curdate()
,'%w')=
0,7,
date_format
(curdate()
,'%w'))
-1)
方法一:
方法二:select subdate
(now()
,weekday
(now()
)-6)
;
12.當前日期前一天,也就是昨天(如果今天是週日獲取的將是下週週日,一般適用於國外)
select subdate
(curdate()
,date_format
(curdate()
,'%w')-
7)同樣要進行判斷處理
select subdate
(curdate()
,if(date_format
(curdate()
,'%w')=
0,7,
date_format
(curdate()
,'%w'))
-7)
13.當前日期後一天,也就是明天select subdate
(now()
,1) as 'yesterday'
select subdate
(now()
, interval -
1 day) as 'tomorrow'
mysql 記錄函式 mysql 函式記錄
條件查詢 case case when then when then when then else end1.簡單case函式寫法 注意 的位置 select case when 1 then 男 when 0 then 女 else 保密 end as text from user 2.case搜...
Mysql函式記錄
1.instr srt,str 函式,得到字元第一次出現所在的位置,位置從1開始 select instr 1234 3 3 2.substring str,num 擷取字串,從索引位置擷取,包括索引位置,位置從1開始 select substring 123 2 23 3.concat str,連...
Mysql 函式記錄
1.一行轉多行 substring index 1 將一行拆分為多行 select a.id,substring index substring index a.ids,b.help topic id 1 1 as ids from inini a join mysql.help topic b o...