• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Converting a Date format?

I am trying to update the format of dates stored within a table they are currently stored as:

2008-10-16

and I would like to convert it to:

16/10/2008

I am storing these as a nvarchar(50)

Any ideas would be great.
0
directxBOB
Asked:
directxBOB
2 Solutions
 
mirzasCommented:
You should store date as datetime type not nvarchar.

anyways... for SQL Server 2005 it looks like this..

SELECT Substring('2008-10-16', 9, 2) + '/' + Substring('2008-10-16', 6, 2) + '/' + Substring('2008-10-16', 1, 4)

you would replace '2008-10-16' with the column name:




UPDATE [TABLE] SET DateColumn = Substring(DateColumn, 9, 2) + '/' + Substring(DateColumn, 6, 2) + '/' + Substring(DateColumn, 1, 4)
 
 
If you give more details about your table I can provide a better query.

Open in new window

0
 
kerwinsiyCommented:
try this
declare @date datetime 
set @date = '2008-10-16'
select convert(varchar(10),@date,103)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now