Reputation: 95
What are the pros and cons for storing a date in a SQL database as a Date datatype versus storing the year, month, day, etc in separate columns using an integer data type? I noticed that the database back end for an application where I work separates all dates into columns of integers for days, months, years. Why would the developers have used this schema?
Upvotes: 0
Views: 93
Reputation: 95751
Some cons . . .
Upvotes: 1
Reputation: 1460
The main idea of using Date data type is that you can comfortably use DB commands like that: GIVE ME records WHERE date from 01-10-2014 08:30 UTC to 04-10-2014 02:30 UTC. In DB system need to look and compare only one field before returning result otherwise system needs to check several columns before returning the result.
I would not recommend you to use few fields for displaying dates. Use classic. :) Such realisation like in your description can be explained only that app doing some special operations with dates.
Upvotes: 1