有关使用 SQL 在 Access 中获取工作日的一些说明。为方便起见,这在列中列出。
SELECT t.Startdate,
DateDiff("d",t.Startdate,Date())-(DateDiff("ww",t.Startdate,Date())*2) AS InaccurateWorkDays,
DateDiff("ww",t.Startdate,Date()) AS WeekEndCount,
Weekday(Date()) AS EndDateWeekDay,
DateDiff("d",t.Startdate,Date()+1) Mod 7 AS Remainder,
IIf([Remainder]>0,
[WeekEndCount]+(([EndDateWeekDay]=7)*-0.5)
+(([EndDateWeekDay]=[Remainder])*-0.5)
+(([EndDateWeekDay]<[Remainder])*-1),
[WeekEndCount]) AS WeekEndCountAdjusted,
[WeekEndCountAdjusted]*2 AS WeekEndDays,
(Date()-t.Startdate)-[WeekEndDays] AS WorkDays
FROM table t
结果
Startdate 1 2 3 4 5 6 7
01/07/2012 15 2 6 6 2.5 5 14
02/07/2012 14 2 6 5 2 4 14
03/07/2012 13 2 6 4 2 4 13
04/07/2012 12 2 6 3 2 4 12
05/07/2012 11 2 6 2 2 4 11
06/07/2012 10 2 6 1 2 4 10
07/07/2012 9 2 6 0 2 4 9
08/07/2012 10 1 6 6 1.5 3 9
12/07/2012 6 1 6 2 1 2 6
18/07/2012 2 0 6 3 0 0 2
- 不准确的工作日
- 周末计数
- 结束日期星期天
- 余
- WeekEndCountAdjusted
- 周末日
- 工作日
基于此处找到的代码:http: //forum.lessthandot.com/viewtopic.php?f=102 &t=2510&p=13924