ASP Code

Create Human Readable Dates with ASP

It's not always natural to read a date as 5/13/05. So with this ASP function, you can modify and re-deliver a date, in a format that we humans are most comfortable reading and referring to. It's called niceDate().

If the date was "05/31/2004"

response.write(niceDate(date()))

would print:
Mon May 31, 2004


'====
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
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image