Access 2010计算工作日数 [英] Access 2010 calculating the number of workdays

查看:155
本文介绍了Access 2010计算工作日数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Access 2010的新手,需要获取工作周中的天数(不包括假期),但要有所不同.我已经能够在互联网上显示的工作日中使用标准的VB代码,并且对于简单的星期一-星期五或星期一-星期六的计算非常有用.我的问题是,如果星期五,星期六和星期日都算作1天,我如何或者可以操纵此代码来计算天数?

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?

示例:计算从2014年11月25日星期二到今天的天数.

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

  1. -今天的日期= 2014年12月1日,星期一;
    -2014年12月1日,星期一= 0;
    -2014年11月30日,星期日= 3;
    -2014年11月29日,星期六= 3;
    -2014年11月28日,星期五= 3;
    -2014年11月27日(星期四)(假日)= 2;
    -2014年11月26日,星期三= 2;
    -2014年11月25日,星期二= 1
  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

因此在上面的示例中,天数为3.

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

推荐答案

如果您需要考虑法定假日,则确实需要使用某种表格.纯粹通过算法解决问题的方法很难管理并且容易失败,主要是因为

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. 固定日期的假日可能在其他日期被观察.例如,如果圣诞节在星期六进行,那么员工可能会在星期五休息一天.
  2. 有些假期日期很难计算.特别地,耶稣受难日被定义为星期五"(至少在加拿大)在春分之后的第一个满月之后的第一个星期日之前."
  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".

以最简单的形式,[DatesTable]可能看起来像这样:

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                   

计算2014年11月25日至2014年11月30日(含)之间的工作日数即可

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;

这篇关于Access 2010计算工作日数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆