When to use VARCHAR and DATE/DATETIME

Why not put screws in with a hammer?

Because it isn’t the right tool for the job.

Some of the disadvantages of the VARCHAR version:

  • You can’t easily add / subtract days to the VARCHAR version.
  • It is harder to extract just month / year.
  • There is nothing stopping you putting non-date data in the VARCHAR column in the database.
  • The VARCHAR version is culture specific.
  • You can’t easily sort the dates.
  • It is difficult to change the format if you want to later.
  • It is unconventional, which will make it harder for other developers to understand.
  • In many environments, using VARCHAR will use more storage space. This may not matter for small amounts of data, but in commercial environments with millions of rows of data this might well make a big difference.

Of course, in your hobby projects you can do what you want. In a professional environment I’d insist on using the right tool for the job.

Leave a Comment