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

  • SEARCH
  • Home
  • 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 6178659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:29:41+00:00 2026-05-24T00:29:41+00:00

i have a column (nvarchar),there are datetimes in there but as a string.I want

  • 0

i have a column (nvarchar),there are datetimes in there but as a string.I want to change that column’s type into smalldatetime but before i want to format all string dates into a same datetime format.But i cant succeed it.Some of them are like this “2007-07-10”,some of them are reverse of this “02.07.2008”. How can i change them into one format for example dd.mm.yyyy.
(ms sql server 2008)

  • 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-24T00:29:42+00:00Added an answer on May 24, 2026 at 12:29 am

    If you only have those 2 formats, this is how you can do it.

    I am assuming

    ‘02.07.2008’ has format ‘dd.mm.yyyy’

    ‘2007-07-10’ has format ‘yyyy-mm-dd’

    If you have more formats than that, you have to alter the ‘case’ in the ‘select’ clause accordingly

    declare @t table (a varchar(12))
    
    insert @t values ('02.07.2008')
    insert @t values ('2007-07-10')
    
    select convert(date, a, case when charindex('-',a) = 5 then 21 else 103 end)
    from @t
    

    Output

    2008-07-02
    2007-07-10
    

    The format is standard for a date field, but if you want to store it as a varchar, you can format it as dd.mm.yyyy like this instead.

    select replace(convert(varchar, convert(date, a, case when charindex('-',a) = 5 
    then 21 else 103 end), 103), '/', '.')
    from @t
    

    Output

    02.07.2008
    10.07.2007
    

    I have to point out that you should always store a date as a date and not a varchar in the database when possible.

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

Sidebar

Related Questions

i have a table that have one column (AbsoluteUrl NVARCHAR(2048)) and i want to
I have a column in a table which is of type nvarchar(max) and there
I have a column of type nvarchar(max) in a table that contains the substring
I have column with varchar values like 022008 that I need to convert into
Hey guys, I have a column in an sql server table that is nvarchar(max).
Basically I have a column named XML that is of type TEXT ; this
I have a column in a table so that it is no longer NVARCHAR(256)
I have a column [Cash] nvarchar(50) that has data that will later be converted
I need to change the data type of a column from nvarchar(50) to nvarchar(MAX).
I have a NVARCHAR(max) column in a table and a stored procedure that would

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.