Best way to save only day and month in database Best way to save only day and month in database database database

Best way to save only day and month in database


I'd choose b), because it more accurately reflects the meaning of the data. Having a data structure where some parts are supposed to be "ignored" is problematic. What if people just do a simple date comparison, assuming the year is always the same, but someone used a different placeholder year, assuming the year doesn't matter anyway?

Always use data structures that reflect your intentions.

That c) is bad is, I believe, beyond reasonable discussion :-). And I'm not thinking of performance reasons...


I would use the date field and even though not needed, would still save the year as well. Just strip it out when you have to print it / use it. There are a few reasons:

  1. You might find out that a laterpoint the customer does want you tosave the date. In that case youdon't have to do any changes to yourdatabase structure.
  2. You can use the SQL date functions to compare dates, if needed. If you have day and month in separate fields, you need a lot more code to e.g. calculate the difference between two dates (leap years etc).

The reasons give for choosing b) can also be easily solved with those SQL date functions. You can easily pick events in a certain month, for instance, in a single query.


I'd choose b), because it would make queries much easier: you'll be able to restore all events in a range (December, specific day, day range) in a very easy manner.If you choose a) - don't forget to set the year to a specific one for comparison and extraction reasons.