[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Converting a Date format?

Posted on 2008-11-05
Medium Priority
Last Modified: 2010-03-20
I am trying to update the format of dates stored within a table they are currently stored as:


and I would like to convert it to:


I am storing these as a nvarchar(50)

Any ideas would be great.
Question by:directxBOB

Accepted Solution

mirzas earned 1800 total points
ID: 22884177
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


Assisted Solution

kerwinsiy earned 200 total points
ID: 22884191
try this
declare @date datetime 
set @date = '2008-10-16'
select convert(varchar(10),@date,103)

Open in new window


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question