Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using varchar instead of date field types in MySQL

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?

like image 677
Darryl Hein Avatar asked Nov 18 '25 22:11

Darryl Hein


1 Answers

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.

like image 105
bobince Avatar answered Nov 21 '25 15:11

bobince



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!