我确定有人已经开发出了在其他编程语言中模拟Excel网络日功能的工作。如果你可以分享的话,你可以选择 。 感谢在sql中模拟Excel networkdays
1
A
回答
1
一个SQL解决方案为每SO质疑"Equivalent of Excel’s NETWORKDAYS function with Jet ADO"
3
的想法是计算每个日期的星期然后采用各种偏移的开始之间的工作日。
- 每个日期前找到周六之间的天数
- 除以7乘以5得到的工作日数
- 偏移总的起始日期是否是结尾日期 后
- 再次偏移量开始是否结束后开始是星期六
- 再次为启动是否是后到底是星期天
- 再次为启动以后是否不和开始是一个星期天
- 为再次启动后,是否不和,到底是周六
添加一些随机的日期到表中。
declare @t table ([start] datetime, [end] datetime)
insert into @t values ('2088-01-14 11:56:23','2011-11-10 03:34:09')
insert into @t values ('2024-09-24 10:14:29','2087-09-16 15:52:06')
然后为这些日期计算NETWORKDAYS。
select [start],[end]
,((datediff(day,0,[end])-datepart(dw,[end]))-(datediff(day,0,[start])-datepart(dw,[start])))/7*5 --[weekdays]
+ datepart(dw,[end]) - datepart(dw,[start]) --[weekday diff]
+ case when datediff(day,0,[start]) > datediff(day,0,[end]) then -1 else 1 end --[start after]
+ case when datediff(day,0,[start]) > datediff(day,0,[end]) and datepart(dw,[start]) = 7 then 1 else 0 end --[start after and start saturday]
+ case when datediff(day,0,[start]) > datediff(day,0,[end]) and datepart(dw,[end]) = 1 then 1 else 0 end --[start after and end sunday]
+ case when datediff(day,0,[start]) <= datediff(day,0,[end]) and datepart(dw,[start]) = 1 then -1 else 0 end --[start not after and start sunday]
+ case when datediff(day,0,[start]) <= datediff(day,0,[end]) and datepart(dw,[end]) = 7 then -1 else 0 end --[start not after and end saturday]
as [networkdays]
from @t
+2
欢迎来到Stack Overflow!在答案中提供至少一个简短的解释和代码是一个好主意。 – Techwolf 2012-11-08 06:32:03
0
对于它的价值,我创建了以下功能的MySQL,它假定周一至周五的工作日:
DROP FUNCTION IF EXISTS BusinessDays;
DELIMITER //
CREATE FUNCTION BusinessDays (startDate DATE, endDate DATE)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE startWeekDay INT;
DECLARE allDays INT;
DECLARE fullWeekCount INT;
DECLARE remainderDays INT;
DECLARE maxPossibleRemainderWeekendDays INT;
DECLARE soloSundays INT;
DECLARE totalBusinessDays INT;
SET startWeekDay = WEEKDAY(startDate);
SET allDays = ABS(DATEDIFF(endDate, startDate)) + 1;
SET fullWeekCount = FLOOR(allDays/7);
SET remainderDays = allDays - (fullWeekCount * 7);
SET maxPossibleRemainderWeekendDays = ROUND(2*(startWeekDay+remainderDays-6)/(ABS(2*(startWeekDay+remainderDays-6))+1))+1;
SET soloSundays = ROUND(2*(startWeekDay-6)/(ABS(2*(startWeekDay-6))+1))+1;
SET totalBusinessDays = allDays - (fullWeekCount * 2) - maxPossibleRemainderWeekendDays + soloSundays;
RETURN totalBusinessDays;
END //
DELIMITER ;
相关问题
- 1. Microsoft Excel 2010 = NETWORKDAYS()
- 2. 使用NETWORKDAYS的Excel VBA
- 3. 在Excel中是否存在与.NETWORKDAYS等效的.NET方法?
- 4. Excel NetWorkdays()内置函数在日语PC中失败
- 5. 在JavaScript中模拟SQL LIKE
- 6. 在.net中模拟Excel Web查询
- 7. 在C中模拟Excel的YearFrac#
- 8. 使用概率在Excel中模拟
- 9. 在C中模拟打开Excel#
- 10. ROW_NUMBER模拟在SQL Server 2000
- 11. 导出sqlite数据库数据在Excel模拟器中的excel
- 12. 在SQL中模拟EXISTS的行为
- 13. 模拟Excel的功能MMULT
- 14. SQL - 模拟器SYSTEM_USER
- 15. SQL Server模拟DBMS_APPLICATION_INFO.SET_MODULE
- 16. 我需要一个函数,它与Excel中的NETWORKDAYS相反或相反
- 17. C#使用T-Sql组模拟Excel数据透视图功能
- 18. Android:在模拟器中模拟WiFi?
- 19. 用C模拟打开excel interop与模拟#
- 20. SQL查询模拟不同
- 21. SQL CE显示列模拟?
- 22. Django的模拟SQL“INNER DJOIN”
- 23. Oracle REGEXP_SUBSTR的SQL Server模拟
- 24. org.powermock.reflect.exceptions.MethodNotFoundException: - 当模拟java sql类
- 25. 如何模拟sql连接?
- 26. SQL模拟一个foreach
- 27. 模拟SQL中的内部对象
- 28. 模拟Python中的SQL Server连接器?
- 29. 在本地模拟SQL Azure环境
- 30. 的PhoneGap 2.0 SQL SELECT在ipad模拟器
[MySQL的函数的可能的复制找到工作日内两个日期之间的数](http://stackoverflow.com/questions/1828948/mysql-function-to-find-the-number-of-working-days-between-two-dates) – 2017-04-21 18:48:51