question

Tan44er avatar image
Tan44er asked

How do I convert yyyymmddhhmmss to mm/dd/yyyy in my select statement

Below you will find my SQL query

select campaign, startdate
from t1

I have in the column startdate values that look like this: yyyymmddhhmmss (e.g.

20170806040000).

I want that the date above shows in my query like this: mm/dd/yyyy (e.g. 08/06/2017).

Unfortunately I am not sure how I have to change my select condition. I tried hundreds of different combinations. However, it is not working. I hope that you guys can help me.

sql querydateconvert
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Jon Crawford avatar image
Jon Crawford answered

what have you tried? doesn't look like your column is a datetime, it's just a numeric value in that format?

If I'm incorrect, then look at CONVERT(varchar(10), ) with style options (I usually use 101, but I'm from the US, assume you use similar notation based on your question)

If it is just a value, then you could SUBSTRING() it and concatenate '/' in where it should go.

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.