Converting varchar to datetime - Prabh

21-Feb-08 05:22:01
I have a table column called separation date with data in this
format:DD/MM/YYYY and sume NULL values.

Now I wat to be this column in datetime format..
I was tryinh toconvert with the following query

SELECT CAST(Separation_date as DATETIME) from TX_Job_History
where I am getting the follwing error:

Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.

Please help me out to solve this..

Thanks in advance.
reply
 
 

Converting varchar to datetime - Uri Dimant

21-Feb-08 05:56:28
Hi
Add ISDATE(col)=1 in WHERE condition. If it does not help, please post
sample data to be tested
reply
 

Converting varchar to datetime - Daniel Crichton

21-Feb-08 06:19:59
Prabha wrote  on Thu, 21 Feb 2008 02:22:01 -0800:







What are your regional settings? Do all the rows have a valid date?

Could be that either the regional settings are causing the date conversion
to read them as MM/DD/YYYY (which will break on any day over 12), or you've
got invalid dates in the column. You might have better luck first using
SUBSTRING to split the dates up and reformat them as YYYYMMDD format which
is non-ambiguous.

--
Dan
reply
 

Converting varchar to datetime - Tibor Karaszi

21-Feb-08 06:49:26
Use CONVERT instead of CAST and specify a third format code that matches the string format of your
data. The format codes are documented in Books Online, CONVERT.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
reply
 

Converting varchar to datetime - Plamen Ratchev

21-Feb-08 10:08:55
Style 103 should do it fine:

SELECT CONVERT(DATETIME, dt, 103)
FROM (SELECT '22/01/2008' UNION
SELECT '25/01/2008' UNION
SELECT NULL) AS D(dt)

HTH,

Plamen Ratchev
http://www.SQLStudio.com
reply
 

Converting varchar to datetime - Madhivanan

23-Feb-08 03:42:21
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/09/24/handle-isdate-wi=
th-care.aspx
reply
 
Replace paragraph sign in sql statement.
promotion
Silverlight    WPF    WCF    WWF    LINQ   
JavaScript    AJAX    ASP.NET    XAML   
C#    VB.NET    VB 6.0    GDI+    IIS    XML   
.NET Generics    Anonymous Methods    Delegate   
Visual Studio .NET    Expression Blend    Virus   
Windows Vista    Windows XP    Windows Update   
Windows 2003 Server    Windows 2008 Server   
SQL Server    Microsoft Excel    Microsoft Word   
SharePoint    BizTalk    Virtual Earth   
.NET Compact Framework    Web Service   

"Everything" RSS / ATOM Feed Parser
How to send and receive messages through message queuing in .Net
How to Read text file as database
SQL Server 2005 Paging Performance Tip
Display code of web page.
Fully Scalable Excel File Importer class for .net using Microsoft Jet driver
Generic Chart Color Manager class that can be used for any charts
Helper class to style the infragistics wingrid
Using Reflection to detemine as Assembly Info in and out.
Helper class to play with Window (Owners and position)
Resolving displayname from the culture using the XmlLanguage and LanguageSpecificStringDictionary class