tags:

views:

35

answers:

3

I have this query at the moment

SELECT 
  year_start_1

FROM 
  table1

But 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

+1  A: 
 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/

anishmarokey
Arithmetic overflow error converting expression to data type datetime.
Andomar
updated answer.
anishmarokey
But the source column actually is an integer, not a string
Andomar
convert won't seem to work i'm using ASP.net VB and it keeps throwing up an error everytime I try and use convert
Jamie Taylor
in sql its converting. nothing to worry about VB or C#
anishmarokey
but adding it into my query in my ASPX page it breaks
Jamie Taylor
A: 

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
Andomar
A: 

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

vgv8