July 6, 2009 at 9:54 am
Exactly as it reads, how can you extract the year in a smalldatetime column.
I what to make a selection on the year in the smalldatetime column,
when I used substring it did not work, it's an invalida argument.
Is there another way to do it, without using a convert or cast?
July 6, 2009 at 9:56 am
DECLARE @dt SMALLDATETIME
SET @dt = '2009/01/01'
SELECT YEAR(@dt)
SELECT DATEPART(yy,@dt)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 6, 2009 at 9:58 am
Like this:
declare @ADateTime smalldatetime;
set @ADateTime = '2009-07-05 09:00:00';
select @ADateTime, year(@ADateTime);
You may want to spend some time reading Books Online (BOL, the SQL Server Help System that may be accessed from SSMS by pressing the {f1} function key).
You want to look up functions.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply