SQL substring and charindex issue

rkrause

Registered User.
Local time
Yesterday, 18:05
Joined
Sep 7, 2007
Messages
343
I have a field called productiondate and the data looks like this 2-1-2012 or 12-25-2011 and its a nvarchar(50) value type.

i want to use substring and charindex to get the day month and year into seperate fields of day month year

so far i can do this below and it gets me the month, but i cant figure out how to get the day and year parsed out.

substring(prod_date,0,charindex('-',prod_date)) as 'month'

 
I don't have a lot of experience with the T-SQL string functions, but I'd do it differently:

Month(CAST('2-25-12' as datetime)) as TheMonth
Year(CAST('2-25-12' as datetime)) as TheYear
Day(CAST('2-25-12' as datetime)) as TheDay
 
i guess that worked just the same, thanks.
 

Users who are viewing this thread

Back
Top Bottom