[AccessD] time window

John W. Colby jwcolby at colbyconsulting.com
Thu Feb 12 20:31:29 CST 2004


This appears to work:

'
'Checks whether a time is "between" two other times
'
Function TimeIsBetween(dteTimeFrom As Date, dteTimeTo As Date,
dteTimeToCompare As Date) As Boolean
    Select Case dteTimeFrom
    Case Is < dteTimeTo
        'Normal window, i.e. 6:00 pm to 11:00 pm
        If (dteTimeToCompare >= dteTimeFrom) _
            And (dteTimeToCompare <= dteTimeTo) Then
            TimeIsBetween = True
        End If
    Case Is > dteTimeTo
        'midnight crossing window, i.e. 6:00 pm to 1:00 am
        If (dteTimeToCompare >= dteTimeFrom) _
            Or (dteTimeToCompare <= dteTimeTo) Then
            TimeIsBetween = True
        End If
    Case Else	'times are the same so now() must equal both
        If (dteTimeToCompare = dteTimeFrom) _
            And (dteTimeToCompare = dteTimeTo) Then
            TimeIsBetween = True
        End If
    End Select
End Function

John W. Colby
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Stuart
McLachlan
Sent: Thursday, February 12, 2004 9:21 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] time window


On 12 Feb 2004 at 21:09, John W. Colby wrote:

> I need to be able to express a pure time window (not date related) from /
to
> and test time() as being between (inside) this time window.  This process
> doesn't work across midnight, i.e. 7:00 pm is "between" 6:00 pm and 1:00
am.
> However if I just do a simple compare - 7:00 PM is >= 6:00 PM but it is
not
> <= 1:00 am.
>
> It looks like a "if time 2 > time 1 then use simple test for time()"  "If
> Time 2 < time 1 then invert the second time comparison"
>
> Has anyone done this already?
>

Since times are actually stored as date/times with an integer part of
0, you can just use:

If time2 < time1 then time2 = time2 + 1
--
Lexacorp Ltd
http://www.lexacorp.com.pg
Information Technology Consultancy, Software Development,System
Support.



_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list