I am trying to enter date only in year format if I use short as datatype it's still a waste of data. I hope there must be some function or something to achieve this.
Asked
Active
Viewed 2,135 times
-1
-
1Provide the sample input and output – PowerStar Jan 18 '17 at 06:06
-
1http://stackoverflow.com/questions/12436743/how-to-extract-only-the-year-from-the-date-in-sql-server-2008 – Mike Hohne Jan 18 '17 at 06:06
-
As per Mike above and store as Short type in SQL only 2 bytes – Justin King Jan 18 '17 at 06:09
1 Answers
1
Just use smallint (Short). Size your data type properly, a two byte int is a better choice. By storing 4 digit years in 4 bytes, you are wasting more resources than just disk space.
For extracting year only use
YEAR(Date) function

S M
- 3,133
- 5
- 30
- 59