Below is some sample code that will greet your visitors based on the hour of the day and the day of the week.
<%
Dim h 'create variable that will store the hour
h=hour(now) 'pass in the date and time to the
hour function as a parameter
If h<12 then
response.write "Hello from Ireland, Top of the morning to ya!"
ElseIf h<18 then
response.write "Good afternoon!"
else
response.write "Good evening!"
end if
%>
Below is our code in action:
Good evening!
The function WeekDay accepts a date as an argument. It returns a number between 1 and 7. Sunday is number 1, being the first day of the week.
<%
Dim DayOfTheWeek
DayOfTheWeek = Weekday(Date) 'create variable to
store the day of the week
If DayOfTheWeek = 1 OR DayOfTheWeek = 7 Then
response.write "Hello, It's the weekend time for a break from ASP"
Else
response.write "Hello, It's work time!"
End If
%>
Below is our code in action:
Hello, it's work time!
For our code above we could also have used the WeekdayName function that will accept a number between 1 and 7 and return the corresponding day.
<%
Dim DayOfTheWeekName
DayOfTheWeekName = WeekdayName(Weekday(Date)) 'create
variable
If DayOfTheWeekName = "Sunday" OR "Saturday" Then
response.write "Hello, It's the weekend time for a break from ASP"
Else
response.write "Hello, It's work time!"
End If
%>
Below is our code in action:
Hello, it's work time!
Other date and time related tutorials:
Read more on the Date, Time and Now VBScript functionsGet the best asp web hosting provider now and save 30%
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.