July 14, 2016 at 8:28 am
Hi,
I am not sure if this is possible but can you convert a string nvarchar(50) to a date.
I need to convert 'May - 2016' to 2016-05-01
Thanks in advance for the help.
Paul
July 14, 2016 at 8:36 am
You could remove the "- " and put an "01 " at the beginning. You'd then be able to cast it as date, subject to your local language settings, of course.
John
July 14, 2016 at 8:38 am
No need to remove the dash (-).
DECLARE @cDate nvarchar(50) = 'May - 2016' ;
SELECT CONVERT( date, '01 - ' + @cDate );
July 14, 2016 at 8:42 am
Thanks for the help. Both solutions worked.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply