SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Convert varchar back into datetime??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ostinoh
Yak Posting Veteran

66 Posts

Posted - 04/24/2013 :  12:19:50  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4604 Posts

Posted - 04/24/2013 :  12:26:18  Show Profile  Reply with Quote
CAST([Invoice Date] AS DATE)
--OR
CONVERT(DATETIME, [Invoice Date], 110)


--Edit: forgot this was 2005.

Edited by - Lamprey on 04/24/2013 12:27:40
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/24/2013 :  13:01:38  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000