Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Because dates are a prickly subject that cause no end of confusion to developers? The example above seems like bad form to me.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top