• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1421
  • Last Modified:

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...
0
matthewkhoury
Asked:
matthewkhoury
  • 3
1 Solution
 
kingsfan76Commented:
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
0
 
Saqib KhanSenior DeveloperCommented:
do it in your SQL statement instead

Select  convert(nvarchar(20), COL_NAME, 112) as MyDate From TableName

then MyDate will return YYYMMDD
0
 
kingsfan76Commented:
oops sM should be sD in this line:

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

Response.write formatDateYMD(Date())
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now