Codefixer - ASP tutorials, resources and software
ASP.NET 3.5/2.0 Hosting – Click Here
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Tuesday 13 May
MembersPro PayPal - ASP Membership software

asp.netPRO “Best ASP.NET Host” – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Date and Time Greetings using VBScript functions

Below is some sample code that will greet your visitors based on the hour of the day and the day of the week.

Hour of the day greeting

<%
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 afternoon!

Day of the week greeting

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 functions
Here's a code snippet to display the day and date (eg. Mon 25 December).
Here's a code snippet to display the day and date with the ordinal suffix (eg. Mon 25th December).
How to get the current month name
Display the dates and times
IsDate Function
The DateDiff DateAdd and DatePart Functions
LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software