Reputation: 8970
I have data in a table I am getting from a 3rd party. The date in the column is in a format I havent seen before.
Here is an example of the date: 2013MO01
This date is Jan, 2013 with MO meaning Month 1
Any easy suggestions on getting the date from that field in the database ?
Upvotes: 0
Views: 51
Reputation: 13089
As @chrono mentioned, you can use SUBSTRING, for example:
DECLARE @t NVARCHAR(100) = '2013MO01'
SELECT CAST(SUBSTRING(@t, 1, 4) + '-' + SUBSTRING(@t, 7, 2) + '-01' AS DATETIME)
Or just replacing the MO string:
SELECT CAST(REPLACE(@t, 'MO', '-') + '-01' AS DATETIME)
Upvotes: 4