Compairing Time

1. Senior Member
Join Date
Dec 1969
Posts
213

Compairing Time

I need to write a check to make sure that the curent time falls within a certain time block. What I need it to do is make sure the curent time is between 10:00 P.M. and 8:00 A.M. I know how to pull the date but am not sure how to make the check. Thanks for the help.

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

RE: Compairing Time

&#060;%<BR>If Time() &#062; TimeSerial( 22,0,0 ) OR Time() &#060; TimeSerial( 8,0,0 ) Then<BR> Response.Write "Between 10PM and 8AM"<BR>End If<BR>%&#062;<BR><BR>You don&#039;t *WANT* to pull the *DATE*! You want *only* the time.<BR><BR>

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

You could also do...

&#060;%<BR>curHour = Hour( Time( ) )<BR>If curHour &#062;= 22 OR curHour &#060; 8 Then<BR> Response.Write "Hour is 10PM or later or is before 8AM"<BR>End If<BR>%&#062;<BR><BR>Whichever makes you happier.<BR><BR>Oh, and there is only one "i" in comparing.<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
213

THanks, one more small question.

Thanks for the help, just got one more small question. I need to offset the time by -4 hours. So would i do this:<BR>&#060;%<BR>curHour = Hour( Time(-4))<BR>If curHour &#062;= 22 OR curHour &#060; 8 Then<BR>Response.Write "Hour is 10PM or later or is before 8AM"<BR>End If<BR>%&#062;

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

Now WHY would you think...

...that would work?<BR><BR>Did you look up the TIME function?<BR><BR>(1) Click on "VBScript Reference" in the left panel of this page.<BR> [ and how come you don&#039;t have that high on your list of Favorites??? ]<BR><BR>(2) Click on "Functions" in the list of topics that appears.<BR><BR>(3) Click on "Time" in the list of functions that appears.<BR><BR>Do you see *ANYTHING* in there that even *SUGGESTS* that the TIME function can take an argument? Much less something that says that this argument will affect the result in the way you are suggesting?<BR><BR>DON&#039;T JUST MAKE UP YOUR OWN IDEAS about what various functions and statements will do! Read the docs!<BR><BR>Now...Try to figure out a way to code that with NO CHANGE to the value of TIME() and NO CHANGE to the value of CURHOUR!<BR><BR>

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

Don't peek! Try it yourself first!

&#060;%<BR>curHour = Hour( Time())<BR>If curHour &#062;= 2 AND curHour &#060; 12 Then<BR> Response.Write "Actual hour is 2AM or later and 11AM or sooner"<BR>End If<BR>%&#062;<BR><BR>Why do you *NEED* to adjust the time of day???<BR><BR>Why not just adjust the limits on that time!<BR><BR>Why subtract 2 hours from 2AM in order to get 10PM instead of just comparing again 2AM in the first place?<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
213

Sorry :(

I looked up both the hour() and time() functions in my "Sam&#039;s Teach your self ASP in 21 days" can cound not find anything on minuplating them with the exeption of useing the dateadd() function and did not think that would work. Sorry :(

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