views:

321

answers:

3

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
A: 

I've seen lots of "Developer turned DBA" type people completely misuse database types, just chock it up to inexperience.

FlySwat
+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