Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to change coloumn varchar to datetime

Author  Topic 

rajesha
Starting Member

36 Posts

Posted - 2002-11-02 : 03:34:57
i have a table in which one coloumn is varchar(30) but it contains

dates in a format 30.08.2002 i want to make that coloumn to datetime

but when am changing that it is giving a error like
Unable to modify table.
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error

converting datetime from character string.

what should i do to change the coloumn from varchar to datetime

SamC
White Water Yakist

3467 Posts

Posted - 2002-11-02 : 08:22:58
The problem with your date format (on my server) is that the day appears first.

print cast ('30.8.2002' as datetime)

fails but

print cast ('8.30.2002' as datetime)

works fine. There may be a way to change the default order of month/day/year or day/month/year using SET DATEFORMAT (see BOL for more information), and I'd like to see your postback if you find out how to use SET DATEFORMAT.

If you're tired of research and are comfortable with a brute force solution, break apart the varchar column 'mydate' and rearrange the data like this:

print cast (substring(mydate, 4,2) + '.' +left(MyDate,2) + right(mydate,5) as datetime)


Sam

Go to Top of Page
   

- Advertisement -