While implementing web applications on top of MySQL database, I’m thinking if it is a good idea to just use string data type to store dates?
For example, I can just store dates as ‘201110191503999’ into database. Also this is convenient to query by date. For example, select * from some_table where the_date like ‘20111019%’
Is there any performance issue if we use string for dates? and are there any advantages for using date/datetime data type?
Thanks in advance!
Always use the column type for what what is needed; if you are using a date, use
DATETIME, if it is a timestamp, useTIMESTAMPand so on.Depending on in what you are coding, all the formatting of the data can be done on the actual page in whatever language you are using.
Also, you can take advantage of MySQL functions such as
NOW(), rather than using the language’s version and then storing it into the database.