• david.ostrander (4/24/2013)


    Hello -

    I have a column in my View script that I convert to varchar(10) and want to convert it back to a date for the output to be in excel. Here is the original line

    CONVERT(VARCHAR(10), d.DocDate, 110) AS [Invoice Date]

    I have tried this line with no luck.

    CONVERT(VARCHAR(10), CONVERT(DATETIME, d.DocDate), 110) AS [Invoice Date]

    Can someone confirm if I have the right lines in the sql liine? Or I'm open to another way of writing it out.

    Thank you

    David

    First, why not just drop the convert to varchar completely. If you are using it to drop the time portion, you will get that back converting back to a datetime value (just 00:00:00.000). If you need the later as a datetime then this works:

    dateadd(dd, datediff(dd, 0, d.DocDate), 0)

    If you still want to go through the convert to varchar, then this:

    CONVERT(DATETIME, CONVERT(VARCHAR(10), d.DocDate, 110)) AS [Invoice Date]