---
title: "mysql 计算工作日"
author: "sdywcd"
date: "2013-08-16T16:25:59Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2013-08-16T16:25:59Z"
id: 1926181
url: "https://sdywcd.iteye.com/blog/1926181"
---

```
DELIMITER $$

drop procedure if exists `pGetWorkDays`$$

create procedure pGetWorkDays(s datetime,e datetime)
begin
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
from
(select datediff(e,s)+1 as days,weekday(s)+1 as wd) as a;
end$$
DELIMITER ;
call pGetWorkDays('2005-01-01','2005-12-31');
```