Home >Database >Mysql Tutorial >统计当前日期距离月底有多少工作日的函数_MySQL

统计当前日期距离月底有多少工作日的函数_MySQL

WBOY
WBOYOriginal
2016-06-01 13:48:101449browse

bitsCN.com
统计当前日期距离月底有多少工作日的函数 今天遇到运营那边有个需求,需要找出注册用户排除周六周日的每日打卡情况(包含不是周六周日的当天),当时的第一反应是想找一个能实现排除周六周日能计算到月底还有多少工作日的函数,找了半天没找到,还是自己写一个吧。我崇拜的王大哥也写了一个,贴出来和大家分享。代码如下:  DROP FUNCTION IF EXISTS count_day_left ; DELIMITER //CREATE FUNCTION count_day_left( f_date DATETIME ) RETURNS INT DETERMINISTIC BEGIN /*    Purpose: 统计指定日期距离月底还有多少个工作日,节假日未排除,用于打卡统计的过滤函数     Useage: select count_day_left('2012-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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn