Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Should I create a field for storing years as an integer field or a char(4) field?
Thank you so much!
Posted

I would think an integer may be useful if you need to perform any sort of calculations / sorting on year.

But finally it could depend on what kind of operations you might intend to perform on the date field in the future.
 
Share this answer
 
Comments
[no name] 17-Apr-11 8:41am    
Thank you so much!
[no name] 17-Apr-11 8:43am    
Please wait before your solution accepted. Just for more answerers paying attention to my question!
For those options integer is far better. But if you want to do date based calculations, why not use date. Just use for example the first day of year as date and month. With date, you wouldn't have to do conversions from int to date etc.
 
Share this answer
 
Comments
[no name] 17-Apr-11 8:41am    
As far as I know, there is some data type calls datetime or smalldatetime, but "date"? I intend to store year form only (with 4 in length), how can I do that with datetime or smalldatetime?
Thank you!
Wendelius 17-Apr-11 10:40am    
There's no data type for year only but for date data type, see: http://msdn.microsoft.com/en-us/library/bb630352.aspx
[no name] 17-Apr-11 8:43am    
Please wait before your solution accepted. Just for more answerers paying attention to my question!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900