Using Month, Day, Year


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/15/2000.

<% Month(Date)%> yields 2 (the current month)
<% Day(Date) %> yields 15 (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 February. 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 Tuesday 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 3
CurWeekDay = WeekdayName(CurWkdNo) ' sets CurWeekDay to Tuesday
%>

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 Tue instead of Tuesday. This is accomplished by adding True in the WeekdayName function:
<% WeekdayName(weekday(date, true) %>
Note: False is the default value and does not have to be included in the WeekdayName function.