Click here to Skip to main content
15,902,887 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What should we take the data type for a column to store date in sql table?
Datetime or varchar?
Posted
Updated 27-Dec-13 19:29pm
v2
Comments
Siva Hyderabad 28-Dec-13 1:39am    
Datetime
Sumit Bhargav 28-Dec-13 1:40am    
Is that a professional way or just to solve the issue?
Christian Graus 28-Dec-13 2:00am    
See my answer. It's because the type exists for a reason, and you should only use varchar if you want to write a database that does not work properly, and is slow. Why are you asking ?

1 solution

Varchar is only used by morons. DateTime, or Date for a date with no time. That's why SQL Server offers them.

Reason not to use varchar

1 - any attempt to work with the values as dates ( what they are ), will involve casting them to date or date time

2 - any attempt to sort columns by date won't work unless you used YYYY-MM-DD.

3 - A varchar column can contain any string, so using it for dates means your data has no integrity, values like 'next Tuesday', 'In Three Weeks' and 'I like cats', are all acceptable.
 
Share this answer
 
v2

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