login about faq

I want to get the year (or month or day) portion from a TSQL (T-SQL) statement. How to do that?

asked Nov 09 '10 at 08:49

guru4us's gravatar image

guru4us
1623

edited Nov 09 '10 at 08:59


There are various ways to do that:

  1. You can use year(), month() or day() function.

    select year(getdate()), month(getdate()), day(getdate())

  2. Or you can use datename() function

    select datename(yyyy,getdate())

  3. Or even you can use more complex way like this

select substring(convert(varchar(20),getdate(),112),1,4) --year

answered Nov 09 '10 at 08:58

guru4us's gravatar image

guru4us
1623

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×5
×4
×2
×1
×1

Asked: Nov 09 '10 at 08:49

Seen: 970 times

Last updated: Nov 09 '10 at 08:59

powered by OSQA