Oct 30 at 6:24am - admin

Suppose you have a date that you would like to work with, but you only need to work with part of that date, such as the month, the day, or the year.
Let's assume that we're working with today's date. This makes it real simple. Of course, you can use a variable to represent any valid date. For example, today is 02/1/2000.

<% Month(Date)%> yields 3 (the current month)
<% Day(Date) %> yields 17 (the current day of the month)
<% Year(Date) %> yields 2000 (the current year)

Now, let's assume that we need the month name, not the month number, which is March. So you can see what's going on, we'll first assign the month number of the current date to a variable, and then format that variable to display the month name:
CurMonth = Month(Date)
CurMonthName = MonthName(CurMonth)

Granted, this is the long way around but may be less confusing to you if you're just starting out. A more efficient way to accomplish the same thing (and this is the way I do it) would be:
<% MonthName(Month(Date))%>

Now, let's assume we need to do something with the day portion of the date. Since I'm forever wondering what day it is (time flies when you're having fun!), I can find out its Friday with a bit of code: First, find out what the day of the week (numerically) it is, based on Sunday being the first day of the week (this can be changed, but Sunday is the default):
CurWkdNo = Weekday(date) ' sets the weekday number to 6
CurWeekDay = WeekdayName(CurWkdNo) ' sets CurWeekDay to Friday

Again, a more efficient way of doing this is:
<% WeekdayName(weekday(date))%>

Now that we've gotten the hang of this, let's abbreviate the day name to Fri instead of Friday. This is accomplished by adding True in the WeekdayName function:
<% WeekdayName(weekday(date, true) %>