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 2000 Forums
 Transact-SQL (2000)
 Varchar to Date

Author  Topic 

tatafrank@hotmail.com
Starting Member

2 Posts

Posted - 2008-05-28 : 14:45:26
Hello,

Im having a hard time getting my SQL query to work. I'm trying to take a field with the format '20080508' stored as varchar and converting it to a date field. I have most of it correct already but its showing the time at the end which i dont want. Here is the statment i have so far:

CONVERT (DateTime, SUBSTRING(GrossOrderShippedReturn.OrderReturnDate, 5, 2) + '/' + RIGHT (GrossOrderShippedReturn.OrderReturnDate, 2) + '/' + LEFT (GrossOrderShippedReturn.OrderReturnDate, 4))

My result is this: "05/08/2008 12:00:00 AM"

Any suggestions on how to get rid of the time at the end? Any help would be great

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-28 : 14:50:18
You can not get rid of the time when using datetime data type. Datetime data type includes both date and time.

If this is for presentation purposes only, then just use style 101 in your CONVERT. But you must use varchar data type.

DECLARE @s varchar(20)

SET @s = '20080508'

SELECT CONVERT(varchar(20), CONVERT(datetime, @s), 101)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

tatafrank@hotmail.com
Starting Member

2 Posts

Posted - 2008-05-28 : 15:08:19
Ok great thanks for the quick replay much appreciated! :)
Go to Top of Page
   

- Advertisement -