I have a manually input date that looks something like this:
Wed Dec 21 19:23:32 2016 ,servername.domain.name.com,Random-String-Of-Text-Goes-Here
It's weird, I know, I can't change the way they're doing things. My goal is to get this date into any format that SQL Server sees as a date. Through a disgusting mess of code, I've managed to get it down to:
Dec 21 19:38:12 2016
substring(LEFT(FIELDVALUE, CHARINDEX(',', FIELDVALUE) - 1),5,LEN(LEFT(FIELDVALUE, CHARINDEX(',', FIELDVALUE) - 1)))
But the problem now is that the time is in between the day and year fields.
It will always be a 3Digit Month, space 2 digit day, space 8 digit time, space 4 digit year.
MON DD HH:MI:SS YYYY
Again, any format that SQL recognizes as a date will work. I'm importing these strings into a second database, and using an Excel macro or something else every time will not work. I imagine another charindex or two and I'll be there, but what I have is already such a mess I'm wondering if there is a better way to do this.
If I understand, your question, your looking to extract the date from the string and reformat it.
And with Format(), you can apply the desired format
Returns