Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6104629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:51:49+00:00 2026-05-23T13:51:49+00:00

I have a table that contains a Date column in varchar format. The date

  • 0

I have a table that contains a Date column in varchar format. The date format varies since it’s the date format of a computer that used our program. For example, I have the following formats:

  1. 10.7.2010
  2. 7/11/2010 7:36:55 AM

I’ve tried using:

SELECT        CONVERT(DateTime, Date, 103) AS Expr1
FROM            MyTable 

But I get an out-of-range datetime value exception for the following line:

7/13/2010 3:33:45 PM

I need a way to convert those values to a unified format. Time and the output format are not important, as long as it’s comparable (when copied to Excel or something. It’s to be used externally, so I don’t mind not changing the actual values in the DB).
The database is MSSQL 2005.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:51:50+00:00Added an answer on May 23, 2026 at 1:51 pm

    You need to read up on MSDN Books Online – topic: CAST and CONVERT.

    This shows you all the possible, supported date formats, e.g.

    CONVERT(VARCHAR(50), GETDATE(), 112)
    

    will convert today’s date into ISO format and you’ll get 20110707 as the output.

    For maximum compatibility, I would recommend the ISO-8601 date format:

    YYYYMMDD
    

    or

    YYYY-MM-DDTHH:MM:SS
    

    Those always work, can always be converted, regardless of your SQL Server’s date, regional and language settings…

    Update:

    Converting your existing strings into DATE or DATETIME depends heavily on your language/regional settings:

    DECLARE @string1 VARCHAR(25) = '10.7.2010'
    DECLARE @string2 VARCHAR(25) = '7/11/2010 7:36:55 AM'
    DECLARE @string3 VARCHAR(25) = '7/13/2010 3:33:45 PM'
    
    SET DATEFORMAT MDY
    
    SELECT 
        CAST(@string1 AS DATE),
        CAST(@string2 AS DATETIME),
        CAST(@string2 AS DATETIME)
    

    Result here is:

    2010-10-07  2010-07-11 07:36:55.000   2010-07-13 07:36:55.000
    

    Dates are interpreted as 7th of October 2010, 11th of July 2011 and 13th of July 2010

    SET DATEFORMAT dmy
    
    SELECT 
        CAST(@string1 AS DATE),
        CAST(@string2 AS DATETIME)
    

    Result here is:

    2010-07-10  2010-11-07 07:36:55.000
    

    Dates are interpreted as tenth of July 2010 and 7th of November 2011

    And of course, converting @string3 to a date with these settings will fail, since it’s trying to interpret it as 7th of the 13th month ….. and there is no 13th month…..

    Because of such ambiguities, I would recommend to always use the ISO-8601 formats, which are clear, standardized, always work, and it’s always defined what date is really represented.

    Update #2:

    Of course, you could also use the ISDATE() function check if a given string can be interpreted as a valid date:

    SELECT DateStr, ISDATE(DateStr) FROM dbo.YourTable
    

    In the case of SET DATEFORMAT DMY, the string value of '7/13/2010 3:33:45 PM' will be recognized as invalid:

    SET DATEFORMAT DMY
    SELECT ISDATE('7/13/2010 3:33:45 PM')
    

    returns 0 as its value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table (T1) in t-sql with a column (C1) that contains almost
I have a table that contains approximately 22000 rows and I used a Boolean
I have a table that contains company names in this format: Name Name ,
I have a table that contains tasks and I want to give these an
I have a table that contains maybe 10k to 100k rows and I need
I have a table that contains some blob fields that I don't want to
This is for MySQL and PHP I have a table that contains the following
I have a products table that contains a FK for a category, the Categories
I have an SQLite table that contains a BLOB I need to do a
I have a database that contains a table that looks a bit like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.