How do i get the year(2009) and month(12) from the string datetime, following give me correct full date but wrong year (1905-07-03 00:00:00.000) and month (1900-01-13 00:00:00.000). I have tried changing YYYY to year and MM to month.
Declare @date dateTime; Declare @CurrentYear datetime; Declare @CurrentMonth datetime; Select @date = CONVERT ( datetime , '20091231' ,112 ); Select @CurrentYear = DATEPART(YYYY,@date); --Select @CurrentYear = YEAR(@Date); <---- still wrong year Select @CurrentMONTH = DATEPART(MM,@date); --Select @CurrentMonth = MONTH(@date); <---- still wrong year select @date as fulldate, @CurrentYear as [year], @CurrentMonth as [Month]; None of the SO suggestions has worked so far.
regards K