开发者

Convert string(integer) to date in SQL

I have this query at the moment

SELECT 
  year_start_1

FROM 
  table1

开发者_StackOverflowBut i need to convert it to date

Currently it outputs just a string like this 20100731 but I want it to look like this 31/07/2010

Any ideas

Thanks

Jamie


 SELECT convert(varchar,   convert(datetime,'20100731'), 103)

for different format: http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/


Convert the column to varchar:

cast(year_start_1 as varchar(16))

Then convert the result to a datetime:

convert(datetime, '20100731', 103)

Combining the two:

select  convert(datetime, cast(year_start_1 as varchar(16)), 103)
from    table1


SELECT convert(datetime, convert(varchar, year_start_1))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜