Enhancing Readability with ASP - What Does 07/13/2004 Mean?
(Page 3 of 4 )
When you print out a date in ASP, by default you'll get the format of MM/DD/YYYY. There are all numeric references, and they are just plain annoying. Let's face it, most of us hate having to translate in our heads which month '07' is. Even though we've known all our lives that there are only 12 months, and have had many years to remember their numeric order, we still catch ourselves thinking “January, February, March, April...” and so on, all the while ticking them off with our fingers.
Now, that takes time, and if I'm quickly glancing at a screen of data, to obtain specific information, I don't feel like wasting time figuring out what the date means. So to cater to this, I've built a function to modify and re-deliver a date, in a format that we humans are most comfortable reading and referring to. It's called niceDate(), and here it is:
'============================================
function niceDate( dt, excludeDay )
'============================================
if not isDate( dt ) then
niceDate = ""
exit function
end if
dim d
d = ""
select case Weekday( dt )
case 1:
d = "Sun "
case 2:
d = "Mon "
case 3:
d = "Tues "
case 4:
d = "Wed "
case 5:
d = "Thur "
case 6:
d = "Fri "
case 7:
d = "Sat "
end select
if typeName( excludeDay ) = "Boolean" then
if excludeDay then d = ""
end if
d = d & MonthName( Month( dt ), true ) & " " & Day( dt ) & ", " & Year( dt ) 'no carriage return here
niceDate = d
end function
In essence, it's fairly simple. There's the initial type-checking, where we prevent errors that would result in trying to extract date information from a non-date string (the good ol' type mismatch error). Then we move into a select statement, where we figure out which day of the week it is, and provide the human-friendly version (after all, nobody knows they hate day #2, they just know that they hate Monday). You also have the option to exclude the day from the output, which is a nice way to shorten the resulting string.
Next: How to Use It >>
More ASP Articles
More By Justin Cook