命令:
成都創(chuàng)新互聯(lián)是一家專業(yè)提供東烏珠穆沁企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、HTML5、小程序制作等業(yè)務(wù)。10年已為東烏珠穆沁眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。
select date_format(curdate(),'%w') from dual;
更多參考:
MySQL中DATE_FORMAT(date, format)函數(shù)可根據(jù)format字符串格式化日期或日期和時(shí)間值date,返回結(jié)果串。
也可用DATE_FORMAT( ) 來格式化DATE 或DATETIME 值,以便得到所希望的格式。根據(jù)format字符串格式化date值。
代碼如下
select?group_date?groupDate?from?(
SELECT
@cdate?input_date,
@last_sat?:=?date_add(date_sub(date_sub(@cdate,interval??day(@cdate)-1?day),interval?1?month),?interval?6-date_format(date_sub(date_sub(@cdate,interval??day(@cdate)-1?day),interval?1?month),'%w')?day)?last_sat,
@this_sat?:=?date_add(date_sub(@cdate,interval??day(@cdate)-1?day),?interval?6-date_format(date_sub(@cdate,interval??day(@cdate)-1?day),'%w')?day)?this_sat,
@next_sat?:=?date_add(date_add(date_sub(@cdate,interval??day(@cdate)-1?day),interval?1?month),?interval?6-date_format(date_add(date_sub(@cdate,interval??day(@cdate)-1?day),interval?1?month),'%w')?day)?next_sat,
@last_point?:=?if(day(@last_sat)-30,date_sub(@last_sat,interval?7?day),@last_sat)?last_point,
@this_point?:=?if(day(@this_sat)-30,date_sub(@this_sat,interval?7?day),@this_sat)?this_point,
@next_point?:=?if(day(@next_sat)-30,date_sub(@next_sat,interval?7?day),@next_sat)?next_point?,
case
when?@cdate?=?@last_point?and?@cdate??@this_point?then
concat(
'W',
datediff(@cdate,@last_point)?div?7?+?1,?'/',
year(@cdate),'-',
if(month(@last_sat)=10,month(@last_sat),concat('0',month(@last_sat)))
)
when?@cdate?=@this_point?and?@cdate??@next_point?then
concat(
'W',
datediff(@cdate,@this_point)?div?7?+?1,'/',
year(@cdate),'-',
if(month(@this_sat)=10,month(@this_sat),concat('0',month(@this_sat))))
else
concat(
'W',
datediff(@cdate,@next_point)?div?7?+?1,'/',
year(@cdate),'-',if(month(@next_sat)=10,month(@next_sat),concat('0',month(@next_sat))))
end
group_date
from??(SELECT?@cdate?:=?#{inputDate})?as?gd
);
mysql SELECT DAYOFMONTH(NOW());
DAYOFWEEK(date)
返回date (1 = 周日, 2 =
周一, ..., 7 = 周六)對應(yīng)的工作日索引。這些索引值符合 ODBC標(biāo)準(zhǔn)。
兩種格式,一種是時(shí)間戳,一種是日期格式
①
SELECT IF(days = 1,"是","不是") as "是否星期天" FROM (SELECT DAYOFWEEK(FROM_UNIXTIME(time,"%Y-%m-%d")) AS days FROM table) tmp;
---time是時(shí)間戳 , days = 1代表星期天
--把time 和 table 替換成你數(shù)據(jù)庫的 字段和表
②
SELECT IF(days = 1,"是","不是") as "是否星期天" FROM (SELECT DAYOFWEEK(date) AS days FROM table) tmp;
---date是日期格式 2017-11-21 , days = 1代表星期天
--把date 和 table 替換成你數(shù)據(jù)庫的 字段和表