Link to home
Start Free TrialLog in
Avatar of matthewkhoury
matthewkhoury

asked on

Type mismatch: 'Format'

Why does this:
Response.Write Format(Date(),"yyyymmdd")

Return this:
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'Format'


My objective is to take a datetime field from SQL Server and convert that date to the following format on, YYYYMMDD.

Thanks in advance...
Avatar of kingsfan76
kingsfan76

format is not a valid vbscript function.  it's best to create a customized function to accomplish this:

function formatDateYMD(sDate)
   dim sY, sM, sD
   sY = Year(sDate)
   sM = Month(sDate)
   sD = Day(sDate)
   if Len(sM) = 1 then sM = "0" & sM
   if Len(sD) = 1 then sM = "0" & sD
   formatDateYMD = sY & sM & sD
end function
ASKER CERTIFIED SOLUTION
Avatar of Saqib Khan
Saqib Khan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oops sM should be sD in this line:

if Len(sD) = 1 then sD = "0" & sD
and test it with:

Response.write formatDateYMD(Date())