Difference Between Two Times

# Thread: Difference Between Two Times

1. Junior Member
Join Date
Dec 1969
Posts
7

## Difference Between Two Times

I&#039;m trying to display messages depending on the time of day. I know that everyone has seen the usual examples of "Good Morning" and the like, but I&#039;m looking for something a little more complicated. For example, I want to display one message if the time is between 9:35 am and 4:15 pm. I originally tried something like:<BR><BR>If hour(time) &#062;= 9 And minute(time) &#062; 35 Or hour(time) =&#060; 4 And minute(time) &#060; 15 Then<BR><BR>But the obvious problem is that something like that does not incorporate times such as 10:15 am, etc.<BR><BR>Is there a function similar to datediff() that can be used for times, or can anyone help me with something that will accomplish what I&#039;m looking to do? Thanks!!!

2. Senior Member
Join Date
Dec 1969
Posts
2,854

## RE: Difference Between Two Times

If time &#062; 9:45 AND time &#060; 16:15 then<BR><BR>wouldn&#039;t that work?<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: Difference Between Two Times

First you need to work on AM/PM<BR><BR>if time() &#062;= "9:35 AM" and time() &#060;= "4:15 PM" Then

4. Senior Member
Join Date
Dec 1969
Posts
11,334

## VBS uses # for date/time

So you want what wassup is doing...

5. Senior Member
Join Date
Dec 1969
Posts
11,334

## Actually

if time() &#062; #9:15# and time() &#060; #16:15# then

6. Junior Member
Join Date
Dec 1969
Posts
7

## RE: Actually

Great!! This one worked exactly as I wanted.<BR><BR>But here&#039;s a follow-up question: What exactly is the # sign doing in that?

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Here:

http://msdn.microsoft.com/library/en-us/script56/html/vbsConstants.asp<BR><BR>http://msdn.microsoft.com/library/en-us/script56/html/vsfctisdate.asp<BR><BR>It&#039;s not well exposed in the VBS docs, but you create "date and time literals" in VBS by surrounding them with #...#.<BR><BR>Basically, doing<BR>&#060;%<BR>someDate = #9/2/2003 1:15:30 PM#<BR>%&#062;<BR> is the same thing (but faster to execute!) as<BR>&#060;%<BR>someDate = CDate( "9/2/2003 1:15:30 PM" )<BR>%&#062;<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•