Format date on ASP

G

Ginni

I have two fields that come in from an access database. I
can't change the way they are formatted in the database,
so have to format them in my script when they come in.
Currently I have them both set to come in as mm/dd/yyyy by
using the following: formatdatetime(trim(oRsWD.fields
("first_day_of_month").value ),0)

How can I get the date to be formatted so it appears 09-
Sep-2003??

Thank you!!
Ginni
 
M

MD WebsUnlimited.com

Hi Ginni,

You'll have to write the code to accomplish this.

function sFormatDate(lDateSerial)
Dim aMonths(12)
dim sDate

aMonths(1) = "Jan"
aMonths(2) = "Feb"
aMonths(3) = "Mar"
aMonths(4) = "Apr"
aMonths(5) = "May"
aMonths(6) = "Jun"
aMonths(7) = "Jul"
aMonths(8) = "Aug"
aMonths(9) = "Sep"
aMonths(10)= "Oct"
aMonths(11)= "Nov"
aMonths(12)= "Dec"

if DatePart("d",lDateSerial) < 10 then sFormatDate = "0"
sFormatDate = sFormatDate & DatePart("d",lDateSerial) & "-"
sFormatDate = sFormatDate & aMonths(DatePart("m",lDateSerial)) & "-"
sFormatDate = sFormatDate & DatePart("yyyy",lDateSerial)

end function


To use the function use

response.write sFormatDate(DateValue("09/12/2003"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top