Access 2010 calculating the number of workdays

蹲街弑〆低调 提交于 2019-12-11 05:19:42

问题


I am new to Access 2010 and need to get the number of days in a workweek excluding Holidays however with a twist. I have been able to use the standard VB code for workdays that appears on the internet and it works great for a simple Monday – Friday or Monday - Saturday calculation. My question is, how can I or is it possible to manipulate this code to calculate the number of days if Friday, Saturday and Sunday all count as 1 day?

Example: Calculate the number of days from Tuesday 11/25/14 to today.

  1. -Today's date = Monday, December 01, 2014;
    -Monday, December 01, 2014 = 0;
    -Sunday, November 30, 2014 = 3;
    -Saturday, November 29, 2014 = 3;
    -Friday, November 28, 2014 = 3;
    -Thursday, November 27, 2014(Holiday) = 2;
    -Wednesday, November 26, 2014 = 2;
    -Tuesday, November 25, 2014 = 1

So in the example above, the number of days would be 3.


回答1:


If you need to account for Statutory Holidays you'll really need to use some kind of table. Purely algorithmic approaches to the problem are difficult to manage and prone to failure, primarily because

  1. Holidays that fall on a fixed date may be observed on some other date. For example, if Christmas falls on a Saturday then employees may get a day off on Friday.
  2. Some holiday dates are difficult to calculate. In particular, Good Friday is defined (here in Canada, at least) as "the Friday before the first Sunday after the first full moon following the Spring Equinox".

In its simplest form, the [DatesTable] could look something like this:

theDate     dayOff  comment         
----------  ------  ----------------
2014-11-21  False                   
2014-11-22  True    Saturday        
2014-11-23  True    Sunday          
2014-11-24  False                   
2014-11-25  False                   
2014-11-26  False                   
2014-11-27  True    Thanksgiving Day
2014-11-28  False                   
2014-11-29  True    Saturday        
2014-11-30  True    Sunday          
2014-12-01  False                   
2014-12-02  False                   

Counting the number of work days between 2014-11-25 and 2014-11-30 (inclusive) would simply be

SELECT COUNT(*) AS WorkDays 
FROM DatesTable 
WHERE theDate Between #2014-11-25# And #2014-11-30#
    AND dayOff=False;


来源:https://stackoverflow.com/questions/27238504/access-2010-calculating-the-number-of-workdays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!