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)
 datetime conversion

Author  Topic 

DLTaylor
Posting Yak Master

136 Posts

Posted - 2008-07-17 : 11:48:12
can anyone tell me the T-SQL syntax to convert a field datatype of;

nvarchar (255) where the date format is yyyyMMdd or 20070625

into a datetime (8) eg. 25/06/2008

Thanks

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-17 : 11:52:13
if it's stored in that format i.e. yyyymmdd then you can just do a cast...

cast(urColumn as datetime)

...or is it just that you want it to look like dd/mm/yyyy and don't really care if it's a real datetime?

Em
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2008-07-17 : 11:52:15
SELECT CONVERT(DATETIME, '20070625')
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-07-17 : 12:16:55
A datetime field simply means that the column data holds a valid date or a null value.

If you are just interested in displaying that date properly then just use the formating options available.

SELECT convert(varchar(20),CONVERT(DATETIME, '20070625'),103)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-17 : 12:40:10
quote:
Originally posted by Vinnie881

A datetime field simply means that the column data holds a valid date or a null value.

If you are just interested in displaying that date properly then just use the formating options available.

SELECT convert(varchar(20),CONVERT(DATETIME, '20070625'),103)



or try to do the formatting at front end application
Go to Top of Page

DLTaylor
Posting Yak Master

136 Posts

Posted - 2008-07-17 : 13:07:33
the cast statement work perfectly - thanks.
and indeed i did want to turn it into an actual date.
Thanks for the great help.
Go to Top of Page
   

- Advertisement -