查询过滤器以显示日期时间范围内的记录

时间:2017-02-25 08:39:38

标签: database ms-access-2010

早上好, 我有一个互联网电路使用情况统计表,提供一个月的5分钟使用情况细分。 例如:

CODE
ID    Time                    InPct    OutPct    InMbps    OutMbps
285    2/1/2010 11:40:00 PM    0.066391    0.102875    0.00102    0.00158
286    2/1/2010 11:45:00 PM    0.090858    0.157753    0.001396    0.002423
287    2/1/2010 11:50:00 PM    0.064748    0.108285    0.000995    0.001663
288    2/1/2010 11:55:00 PM    0.062174    0.092498    0.000955    0.001421
289    2/2/2010 12:00:00 AM    0.348073    0.167378    0.005346    0.002571
290    2/2/2010 12:05:00 AM    0.230889    0.264634    0.003546    0.004065
291    2/2/2010 12:10:00 AM    0.094604    0.150474    0.001453    0.002311
292    2/2/2010 12:15:00 AM    0.140493    0.136141    0.002158    0.002091
293    2/2/2010 12:20:00 AM    0.092592    0.128323    0.001422    0.001971
294    2/2/2010 12:25:00 AM    0.190524    0.122717    0.002926    0.001885
295    2/2/2010 12:30:00 AM    0.074951    0.097418    0.001151    0.001496

我想要做的是在每天的2/2/2010 2:30 PM到2/3/2010 9:00 AM之间查询使用情况统计信息(日期是可变的)。日期/时间存储在单个字段中。尝试指定日期() - 1#2:30:00 PM#和date()#9:00:00 AM#之间的条件时,运行查询时不会产生任何结果。我在这里做错了吗?我需要将时间分配到自己的领域吗? 任何帮助都非常感谢。 谢谢,

1 个答案:

答案 0 :(得分:0)

如何在周末的某个周末之后(或之前)获得工作日:

Public Function DateSkipWeekend( _
  ByVal datDate As Date, _
  Optional ByVal booReverse As Boolean) _
  As Date

' Purpose: Calculate first working day equal to or following/preceding datDate.
' Assumes: 5 or 6 working days per week. Weekend is (Saturday and) Sunday.
' Limitation: Does not count for public holidays.
'
' May be freely used and distributed.
' 1999-07-03, Gustav Brock, Cactus Data ApS, Copenhagen

  Const cintWorkdaysOfWeek As Integer = 5

  Dim bytSunday   As Byte
  Dim bytWeekday  As Byte

  bytSunday = Weekday(vbSunday, vbMonday)
  bytWeekday = Weekday(datDate, vbMonday)

  If bytWeekday > cintWorkdaysOfWeek Then
    ' Weekend.
    If booReverse = False Then
      ' Get following workday.
      datDate = DateAdd("d", 1 + bytSunday - bytWeekday, datDate)
    Else
      ' Get preceding workday.
      datDate = DateAdd("d", cintWorkdaysOfWeek - bytWeekday, datDate)
    End If
  End If

  DateSkipWeekend = datDate

End Function

在查询中:

Select 
    ID,
    DateSkipWeekend([Time]) As Workday,
    InPct,
    OutPct,
    InMbps,
    OutMbps
From
    YourTable
Where
    [Time] Between 
        DateAdd("d", -1, Date()) + #2:30:00 PM# 
        And 
        Date() + #09:00:00 AM#