You're right, I just gave another method. I think the calculation is wrong in both cases.
The days portion of the string is the day of the year. If we start at the 1st day, our calculation is one day off. Since 1/0/YYYY is not a valid date, we would have to subtract 1.
Please correct me if I am wrong.
Correct Example:
DECLARE @str varchar(8)
SET @str = '010-2001'
SELECT DATEADD(d, CONVERT(smallint, SUBSTRING(@str, 1, 3)) - 1, CONVERT(datetime, '1/1/' + SUBSTRING(@str, 5, 4)))
Adam Gossage
Lake Wylie, SC, USA
|