Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Convert varchar back into datetime??

Author  Topic 

ostinoh
Yak Posting Veteran

66 Posts

Posted - 2013-04-24 : 12:19:50
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

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-04-24 : 12:26:18
CAST([Invoice Date] AS DATE)
--OR
CONVERT(DATETIME, [Invoice Date], 110)


--Edit: forgot this was 2005.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-24 : 13:01:38
why not do this if attempt was to strip off timepart?

DATEADD(dd,DATEDIFF(dd,0,d.DocDate),0)

format you can always get in way you want at front end by applying format functions

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -