PC Review


Reply
Thread Tools Rate Thread

Check time value

 
 
Lars Brownies
Guest
Posts: n/a
 
      15th Dec 2009
In VBA I need to check whether the current time is after 8 in the evening
but before 4 in the morning. I looked at the time methods but I can't figure
out how to do this check. Can someone point me in the right direction?
Thanks,
Lars

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      15th Dec 2009
"Lars Brownies" <(E-Mail Removed)> wrote in message
news:hg8h15$2rip$(E-Mail Removed)...
> In VBA I need to check whether the current time is after 8 in the evening
> but before 4 in the morning. I looked at the time methods but I can't
> figure out how to do this check. Can someone point me in the right
> direction?



By "current time", do you mean the time of day as reported by the system
clock? If so, try this:

Dim dtTimeNow As Date

dtTimeNow = Time()

If (dtTimeNow >= #8:00 PM#) Or (dtTimeNow < #4:00 AM#) Then
' The time is between 8 PM and 4 AM
Else
' It isn't.
End If

Notice that I have assumed that "after 8 in the evening" includes the time
of 8:00 PM, but "before 4 in the morning" does *not* include the time of
4:00 AM. That may or may not be what you had in mind. If it's not, you can
modify the comparison operators in the If statement.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
Lars Brownies
Guest
Posts: n/a
 
      15th Dec 2009
Thanks Dirk. That's it!

Lars

"Dirk Goldgar" <(E-Mail Removed)> schreef in bericht
news:OhKJu#(E-Mail Removed)...
> "Lars Brownies" <(E-Mail Removed)> wrote in message
> news:hg8h15$2rip$(E-Mail Removed)...
>> In VBA I need to check whether the current time is after 8 in the evening
>> but before 4 in the morning. I looked at the time methods but I can't
>> figure out how to do this check. Can someone point me in the right
>> direction?

>
>
> By "current time", do you mean the time of day as reported by the system
> clock? If so, try this:
>
> Dim dtTimeNow As Date
>
> dtTimeNow = Time()
>
> If (dtTimeNow >= #8:00 PM#) Or (dtTimeNow < #4:00 AM#) Then
> ' The time is between 8 PM and 4 AM
> Else
> ' It isn't.
> End If
>
> Notice that I have assumed that "after 8 in the evening" includes the time
> of 8:00 PM, but "before 4 in the morning" does *not* include the time of
> 4:00 AM. That may or may not be what you had in mind. If it's not, you
> can modify the comparison operators in the If statement.
>
> --
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
>
> (please reply to the newsgroup)
>

 
Reply With Quote
 
Jerry Whittle
Guest
Posts: n/a
 
      15th Dec 2009
Debug.Print Now() > (Date() + 0.833333333333333) and Now() < (Date() +
1.166666666666667)

or

Debug.Print Now() > DateAdd("h", 20,Date()) AND Now() < DateAdd("h",
28,Date())

--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Lars Brownies" wrote:

> In VBA I need to check whether the current time is after 8 in the evening
> but before 4 in the morning. I looked at the time methods but I can't figure
> out how to do this check. Can someone point me in the right direction?
> Thanks,
> Lars
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom real time, time format check bear Microsoft Outlook VBA Programming 1 12th Mar 2010 11:28 PM
Check if a time is past a certain time Savio Microsoft Excel Misc 3 31st Jan 2009 10:21 PM
Internet Explorer PC Time check vs Mozilla PC Time check different =?Utf-8?B?S29uIENlcm4=?= Windows XP General 1 4th May 2005 01:20 PM
Please check this "demo time check" procedure and suggest improvements! Gunnar Johansson Microsoft Excel Programming 1 13th Nov 2004 04:27 PM
Excel Formula help (Check if a time falls between to time arguments) Healingbear Microsoft Excel Misc 1 28th Jan 2004 10:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:45 AM.