Thursday, March 8, 2012

Datetime Conversion

In a table I have a column named DTTM_RCD_ADDED of type varchar with a length of 14. The format of the column is:
YYYYMMDDHHMMSS.
What I would like to do is output:
DD-MM-YYYY HH:MM:SS

I have tried to cast and convert this column but nothing is working. Please help.

Using SQL Server 2000The closest thing that I have is this statement:

CONVERT(smalldatetime, SUBSTRING(C.DTTM_RCD_ADDED, 1, 8), 120)

The problem with this is that it has the HH:MM:SS but they are all zeros. When I use
CONVERT(smalldatetime, SUBSTRING(C.DTTM_RCD_ADDED, 1, 14), 120)
or completly get rid of the substring part I get an error.

No comments:

Post a Comment