Is there any reason to use a varchar field instead of a date field in MySQL? I'm looking at an existing site and I see the developer has done this. Is there any reason to?
+1
A:
Because dates are a prickly subject that cause no end of confusion to developers? The example above seems like bad form to me.
spender
2008-11-12 00:54:22
A:
I've seen lots of "Developer turned DBA" type people completely misuse database types, just chock it up to inexperience.
FlySwat
2008-11-12 00:58:53
+8
A:
Unless it really is acting primarily as a string — say, it wants to preserve date formatting style, locale-named months, named timezones etc. and doesn't care about being computable — no, varchar would not be a good choice.
Handling real date datatypes can be problematic/non-portable across different DBMSs/data access layers, but the usual solution to that is just to use an integer (Unix-style) timestamp instead.
bobince
2008-11-12 00:58:56