﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by fediori  / Converting to datetime a char field with several possible date formats / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 12:18:50 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Converting to datetime a char field with several possible date formats</title><link>http://www.sqlservercentral.com/Forums/Topic1419310-2632-1.aspx</link><description>Glad to help.  Thank you for the feedback.</description><pubDate>Mon, 15 Apr 2013 16:18:35 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Converting to datetime a char field with several possible date formats</title><link>http://www.sqlservercentral.com/Forums/Topic1419310-2632-1.aspx</link><description>Thanks a lot, I did not know about SET DATEFORMAT</description><pubDate>Mon, 15 Apr 2013 01:34:54 GMT</pubDate><dc:creator>Federico Iori</dc:creator></item><item><title>RE: Converting to datetime a char field with several possible date formats</title><link>http://www.sqlservercentral.com/Forums/Topic1419310-2632-1.aspx</link><description>Thanks for sharing your code but it just doesn't need to be so complex a thing.  SQL Server will handle all sorts of date formats without any help.  The only time it really runs into a problem is where you have DMY and MDY formats in the same column so it wouldn't be able to figure out if 3/7/2005 is in March or July in a mixed column... just like your code won't be able to.For code that follows one standard (eithe DMY or MDY) in a given column.  No special processing for format is needed.  For example:[code="sql"]SET DATEFORMAT DMY SELECT SomeStringDate,       ConvertedToDateTime = CAST(d.SomeStringDate AS DATETIME)   FROM (         SELECT '15-03-05'      UNION ALL         SELECT '15/03/08'      UNION ALL         SELECT '15/03/2005'    UNION ALL         SELECT '15.03.2005'    UNION ALL         SELECT 'March 15 2005' UNION ALL         SELECT 'Mar 15 2005'   UNION ALL         SELECT '15 March 2005' UNION ALL         SELECT '15 Mar 2005'   UNION ALL         SELECT '20050315'        ) d (SomeStringDate);[/code]</description><pubDate>Sun, 14 Apr 2013 16:49:49 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>Converting to datetime a char field with several possible date formats</title><link>http://www.sqlservercentral.com/Forums/Topic1419310-2632-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/T-SQL/96816/"&gt;Converting to datetime a char field with several possible date formats&lt;/A&gt;[/B]</description><pubDate>Tue, 12 Feb 2013 23:52:43 GMT</pubDate><dc:creator>Federico Iori</dc:creator></item></channel></rss>