SELECT
	(
		floor( days / 7 )* 5 + days % 7 -
	CASE
			
			WHEN 6 BETWEEN wd 
			AND wd + days % 7-1 THEN
				1 ELSE 0 
				END -
		CASE
				
				WHEN 7 BETWEEN wd 
				AND wd + days % 7-1 THEN
					1 ELSE 0 
				END 
				) AS result 
		FROM
(select datediff(e,s)+1 as days, weekday(s)+1 as wd ) as a; 

e为结束时间,s为开始时间,格式为

2018-09-02

 

转载Mysql 编程实战三之计算两个日期的工作日数_数据库_IT虾米网

侵删

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐