Abhinav Khichar Abhinav Khichar - 2 months ago 11
SQL Question

How to convert timestamp to date in SQL?

Image: http://i.stack.imgur.com/CyyHo.jpg

I have a dataset as shown in the image. I want to use the values of created_date column as

datetime
format. How can i do that?

Answer

Column values does not seems to be a TimeStamp. Use the below script to make the values as datetime .

    SELECT credits,amount,city,
                  CONVERT(DATETIME,LEFT(created_date,8)
                  +' '+SUBSTRING(created_date,9,2)
                  +':'+SUBSTRING(created_date,11,2)
                  +':'+RIGHT(created_date,2)) Created_Date
    FROM YourTable