Show based on time of day

August 18, 2008 by Carl Grint

I am not sure you really would need to go as far as an extension, it is relatively easy to show content based on the time or period of time of a day, using DatePart.

The varibles for DatePart are

Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second

 

DatePart("h", Now()) 

would give you the current hour, so you would then simply use an IF statement to say if the hour was between lets say 9 and 5 show.

For example:

Dim varCurrenthour

varCurrenthour=DatePart("h", Now())

If varCurrenthour >=9 AND varCurrenthour <17 Then Response.Write("Mobile: 01245 786544") 

DatePart examples at W3School/MS

August 18, 2008 by Carl Grint

Also, check out http://www.w3schools.com/VBscript/func_datepart.asp and http://msdn.microsoft.com/en-us/library/aa262714.aspx