Mysql – How to keep “approximate” date data points

database-designMySQL

I'm working on a web app that displays some products with their release date. Some dates are complete (for example, '2017-09-05') and some are not (for instance, 'first 2018 quarter', '2018 september', '2019').

The existing database is built on MySQL and I want to keep requests “simple”.
Sometimes I need to request (a) released products, sometimes (b) future products, and sometimes (c) all products.

The questions

How can I (1) retain and (2) manipulate these incomplete date data points? In the same date column? In which format?

Best Answer

There is no "standard" way. You need to invent something, then write app code to handle it. Some thoughts:

  • Strings like what you suggest. Pro: displays nicely; Con: hard to parse.
  • Strings, but more like 2018Q1, 201809, or whatever. Pros/cons: Somewhat readable; somewhat parsable.
  • DATE, with the day of the beginning (or end?) of the period, plus another column that says day or month or quarter or annual. That could be an ENUM or some other technique. Pro: somewhat sortable.