Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Select Case between 2 datetime values 3

Status
Not open for further replies.

LakotaMan

Instructor
Aug 21, 2001
240
US
Hi all,
I am trying to write a little code to analyze the current time when a button on my form is clicked. I need to know if the current time is between 12:00 pm and 6:00 pm, or between 6:01 pm and 12:59 pm.

I am using a variable called TimeOfDay to capture just the hourly info of Now(), and a step-through shows me I am getting the value I want for this (i.e. 1:08.00 PM).

Here’s what I have been trying to do:
Code:
            Select Case TimeofDay
                Case Is > #12:00:00 PM# < #6:00:00 PM#
                    Greeting = "Good Afternoon"
                Case Is > #6:01:00 PM# < #11:59:00 PM#
                    Greeting = "Good Evening"
                Case Else
            End Select
I tried using "between" but couldn't get the syntax right, so I borrowed this from another posting, and it's probably obvious to you why it's not working, but any help you can give me will be greatly appreciated.

Thanks,
LM
 


hi,
Code:
    Select Case TimeofDay
        Case Is >= #6:00:00 PM#
             Greeting = "Good Evening"
        Case Is >= #12:00:00 PM#
             Greeting = "Good Afternoon"
         Case Else
            Greeting = "good morning"
     End Select

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Code:
Select Case TimeofDay
    Case Is > #6:00:00 PM#
        Greeting = "Good Evening"
    Case Is > #12:00:00 PM#
        Greeting = "Good Afternoon"
End Select
With your method, it will never look at the 2nd case, because the 1st case will have been satisfied. However, what do you want to do if the time of day is before 12 PM?


Randy
 
Skip & Randy,

Thank you SO MUCH for setting me straight! What a dummy I are :)

Have a GREAT weekend!

LM
 
I think I would go for:

Code:
            Select Case timeofday
                Case #12:00:00 PM# To #5:59:59 PM#
                    Greeting = "Good Afternoon"
                Case #6:00:00 PM# To #11:59:59 PM#
                    Greeting = "Good Evening"
                Case Else
            End Select

 
Remou,

Thanks to you also, now I can't decide --are there advantages to using one fo these versions over the other?

LM
 



there's almost always more than one way to skin a cat.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top