Type mismatch: 'Format'

Posted on 2005-04-06
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...
Question by:matthewkhoury
    LVL 12

    Expert Comment

    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
    LVL 23

    Accepted Solution

    do it in your SQL statement instead

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

    then MyDate will return YYYMMDD
    LVL 12

    Expert Comment

    oops sM should be sD in this line:

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

    Expert Comment

    and test it with:

    Response.write formatDateYMD(Date())

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now