Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date field conversion help 1

Status
Not open for further replies.

Rene1024

MIS
Jul 24, 2003
142
US
I have a varchar field that looks like this:
DOB = 19800101 it needs to be a date time field.
I need to convert it to DOB = '01/01/1980'

I already created a new datetime column and now I need to update the new column with the information from the old DOB Column.

How do I do this?

Thanks.

Rgds.
Rene
 
Just insert it into the field. I have a table called TEST and a field defined as a DateTime called Tfield. If I use you date example it will look something like this ...

-- Here is an Insert example

insert into TEST (Tfield) values ('19800101')

-- Here is an Update example

UPDATE TEST
SET Tfield = '19800101'
Where ColumnA = 'WhatEver'

Remember ... SQL Server stores dates in only on form. If you want to pull the dates out of SQL Server in different formatted ways, you have to use a CONVERT statement w/ a Style. A Style is a numeric parameter that tells the CONVERT statement how you want to see the outputted date string. Here is an example ...

SELECT CONVERT(Char,Tfield,101)
FROM TEST

OR

SELECT CONVERT(Char,Tfield,112)
FROM TEST

Take a look at Books OnLine for the different Styles you have to choose from and the use and application of DateTime fields.

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top