?
Solved

Type mismatch: 'Format'

Posted on 2005-04-06
4
Medium Priority
?
1,396 Views
Last Modified: 2008-02-07
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
Comment
Question by:matthewkhoury
  • 3
4 Comments
 
LVL 12

Expert Comment

by:kingsfan76
ID: 13721991
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
 
LVL 23

Accepted Solution

by:
Saqib Khan earned 400 total points
ID: 13722006
do it in your SQL statement instead

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

then MyDate will return YYYMMDD
0
 
LVL 12

Expert Comment

by:kingsfan76
ID: 13722008
oops sM should be sD in this line:

if Len(sD) = 1 then sD = "0" & sD
0
 
LVL 12

Expert Comment

by:kingsfan76
ID: 13722021
and test it with:

Response.write formatDateYMD(Date())
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question