Using Month, Day, YearSuppose 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)
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:
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:
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):
Again, a more efficient way of doing this is:
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:
|