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)
 Converting Date formats

Author  Topic 

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2008-11-05 : 05:36:18
I have a problem with a date on my server it reads 1081031 and I want to convert this to 31/10/2008. I have searched google to I am googled out can any one help.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-05 : 06:19:27
What datatype is the column?
INT? VARCHAR?



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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-05 : 06:24:42
[code]DECLARE @Sample VARCHAR(20)

SET @Sample = '1081031'

SELECT RIGHT(@Sample, 2) + '/'
+ LEFT(RIGHT(@Sample, 4), 2) + '/'
+ CASE WHEN @Sample LIKE '1[0-9][0-9][0-9][0-9][0-9][0-9]' THEN '20' ELSE '19' END
+ LEFT(RIGHT(@Sample, 6), 2)[/code]


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

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2008-11-05 : 06:53:02
Sorry I forgot that its a decimal 12,0

Whitmoj
If you are in a hurry you will never get there
Go to Top of Page

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2008-11-05 : 07:07:11
This works fantastic thanks Peso

Whitmoj
If you are in a hurry you will never get there
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-05 : 07:34:39

Better change it to proper datetime value and leave formation to front end

DECLARE @Sample VARCHAR(20)

SET @Sample = '1081031'

select cast(case when @sample like '1%' then '20' else '19' end+RIGHT(@Sample,6) as datetime)



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -