I have a date that sometimes can be only a year, years and month or a full date. What is the best practice to save it on the db?
I need to do search later as: Give me all date between 2004 - 2008 or give me all date between 2004-05-21 to 2005-12-31
I have a date that sometimes can be only a year, years and month or a full date. What is the best practice to save it on the db?
I need to do search later as: Give me all date between 2004 - 2008 or give me all date between 2004-05-21 to 2005-12-31
I would suggest to use DATE
format (https://dev.mysql.com/doc/refman/5.5/en/datetime.html) and then if needed use more specific functions to query records by date ranges like
WHERE YEAR(created) BETWEEN 2010 AND 2011
etc.
More date\time related functions here: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html