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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update date feild switch format 1

Status
Not open for further replies.

alexanderthegreat

IS-IT--Management
Joined
Sep 9, 2005
Messages
70
Location
US
how can I update my field licissuedate from date fields which look like this 20030520 to the short date format 05/20/2003? in my table garages
 
If your field is datetime or smalldatetime, SQL Server does NOT store dates and times in those fields as recognizable values. You can only set the format by 1) storing the date in a string format (VARCHAR/CHAR) or 2) by setting how it is to be displayed (using CONVERT). Refer to FAQ183-5834 for more information.

-SQLBill

Posting advice: FAQ481-4875
 
here is an example

declare @v varchar(20)
select @v ='20030520'

select convert(varchar,convert(datetime,@v),101)

your update query would be like this

update table
set field = convert(varchar,convert(datetime,field),101)

Denis The SQL Menace
SQL blog:
Personal Blog:
 
update garages
set licissuedate = convert(varchar,convert(datetime,licissuedate),101)

Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
 
you have to fix those invalid dates or do something like

update garages
set licissuedate = convert(varchar,convert(datetime,licissuedate),101)
where isdate(licissuedate) =1

If you don't want to fix them

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top