计算月份的双休日
create function f_ygGetWeekEndCount(inMonth int(11))
RETURNS int
begin
declare weekEndCount int(2) default 0;-- 要计算的月份拥有周六日的天数
DECLARE monthCount int(5);-- 要计算的月份拥有的天数
DECLARE tempDay VARCHAR(10);
declare myInMonth varchar(10);
set myInMonth=FROM_UNIXTIME(inMonth);
set monthCount= DAYOFMONTH(last_day(myInMonth));
while monthCount>0 DO
set tempDay=substr(myInMonth,1,8);-- 取得年月‘2015-01-’格式
set tempDay=CONCAT(tempDay,monthCount);-- 加上月拥有天数便是‘2015-01-31’
IF(DAYOFWEEK(tempDay)=1 or DAYOFWEEK(tempDay)=7)THEN -- 如果dayofweek(time)返回是1和7便是周六和周日那weekEndCount+1
set weekEndCount=weekEndCount+1;
ELSE
set weekEndCount=weekEndCount;
end if;
set monthCount=monthCount-1;-- 循环一次后天数减1直到为0为止
end WHILE;
return weekEndCOUNT;
end