Format Dates: mm/dd/yyyy instead of m/d/yy

I was asked today to provide a function for another developer to cleanly convert Date values returned from a database query via ASP. The function need to display dates similar to this format: 01/01/2026 instead of the database format 1/1/01.

I was asked today to provide a function for another developer to cleanly convert Date values returned from a database query via ASP. The function need to display dates similar to this format: 01/01/2026 instead of the database format 1/1/01. Here is the function in ASP along with a few sample function calls:

<%

function ConvertDate(sDate)

dim sMM
dim sDD

if Trim(sDate) = "" then Exit Function

sMM = Month(CDate(sDate))
sDD = Day(CDate(sDate))
if Len(Trim(sMM)) < 2 then sMM = "0" & sMM
if Len(Trim(sDD)) < 2 then sDD = "0" & sDD

ConvertDate = sMM & "/" & sDD & "/" & Year(CDate(sDate))

end function

response.write ConvertDate("8/1/65 10:00") & "<br>"
response.write ConvertDate("8/01/85") & "<br>"
response.write ConvertDate("1/1/01")

%>


Submission Date:  9/23/2005 3:02:06 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (867 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP
Here's my most recent course on Pluralsight. I think it has some interesting insight on IT professional job interviews and using words in your resume to influence the questions you'll be asked. Resumes, Job Seeking, and Interviews in context.