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 2005 Forums
 Transact-SQL (2005)
 Convert Date

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-03-01 : 04:47:01
hi,
i have a column of TYPE DateTime like:2009-01-05 00:00:00.000
i want to be 05-01-2009 in column of Type DateTime

how can i do it?
i write this query:

SELECT
Convert(DateTime,Convert (Varchar,Date,103)) As Date
FROM TABLE

this error:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-01 : 04:48:21
This is nothing else but a presentation issue.
Presentation should be handled at the client side, not the database side.
Leave datetime as is.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-03-01 : 05:02:43
i need that to be in the DB
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-01 : 05:09:15
ALTER TABLE Table1
ADD newDate AS Convert(char(10), Date, 103))



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-01 : 23:51:55
declare @date datetime
set @date ='2009-01-05 00:00:00.000'

select @date, replace(convert(varchar(10),@date,103),'/','-'),convert(datetime,replace(convert(varchar(10),@date,103),'/','-'))
Go to Top of Page

Mangal Pardeshi
Posting Yak Master

110 Posts

Posted - 2009-03-02 : 00:33:52
[code]
DECLARE @DATE DATETIME
SET @DATE ='2009-01-05 00:00:00.000'


SELECT
Convert (Varchar(10),@Date,105) As Date
[/code]

http://mangalpardeshi.blogspot.com/2008/11/date-formats-in-sql-server.html

Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page
   

- Advertisement -