question

DataJoe avatar image
DataJoe asked

How do you convert a date to a string?

I have field with date format that I need to move to another table that is in a fixed all char layout. I thought this would be straight forward but seems to be eluding me. Source is YYYY-MM-DD and I want to end up with YYYYMMDD text. Thank you for what should be simple.
date-format
10 |1200

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

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered
If the field you're selecting is a DATE field, then something like: SELECT CONVERT(VARCHAR(8), MyDateField, 112) FROM MyTable might be the way to go. See [`CONVERT`][1] documentation for the various date format parameter options [1]: http://msdn.microsoft.com/en-us/library/ms187928.aspx
1 comment
10 |1200

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

DataJoe avatar image DataJoe commented ·
Like I said, straight forward and I thought I tried this yesterday but this worked like a champ! Thank you.
1 Like 1 ·

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.