Count the number of working days between the current date and the end of the month. If you have a requirement on the Operation side today, you need to find out the registration users who want to exclude the daily logging on Saturday and Sunday (including not the day of Saturday ), at that time, the first response was to find a function that could exclude the number of working days that can be calculated by the end of the month on Saturday and Sunday. If I hadn't found it for half a day, I 'd like to write it myself. I also wrote one of my favorite Big Brother Wang and posted it to share it with you. The Code is as follows: www.2cto.com drop function if exists count_day_left; DELIMITER // create function count_day_left (f_date DATETIME) returns int deterministic begin/* Purpose: counts the number of working days before the end of a specified date, the filtering function Useage for logging statistics is: select count_day_left ('2017-09-10 '); */DECLARE start_day INT; DECLARE end_day INT; DECLARE count_day int default 0; DECLARE tmp_date date default date (f_date); SET end_day = DAY (LAST_DAY (f_date); SET start_day = DAY (f_date ); WHILE start_day <= end_day do if (DAYOFWEEK (tmp_date) = 1) OR (DAYOFWEEK (tmp_date) = 7) then set tmp_date = DATE_ADD (tmp_date, INTERVAL 1 DAY ); SET start_day = start_day + 1; else set tmp_date = DATE_ADD (tmp_date, INTERVAL 1 DAY); SET start_day = start_day + 1; SET count_day = count_day + 1; end if; end while; RETURN count_day; END // DELIMITER; Revoke drop function if exists count_day_left; DELIMITER // create function count_day_left (f_date DATE) returns intreads SQL DATABEGINRETURN DATEDIFF (LAST_DAY (f_date), f_date) -(WEEK (LAST_DAY (f_date)-WEEK (f_date) * 2 + IF (WEEKDAY (f_date) = 6, 0, 1)-IF (WEEKDAY (LAST_DAY (f_date )) = 5, 1, 0); END // DELIMITER;