What is the best way to store user BIRTHDATES in MySQL/PHP and why?
I’m currently storing it as a VARCHAR(10) in the following format:
MM-DD-YYYY
…but I have a feeling this isn’t the best way, especially since I sometimes see invalid years in that field.
Please don’t just say what the best method is, also explain why it’s the best method so that I can be convinced to change the entire way birthdates are handled on my site, which is a huge undertaking should that be needed.
Thanks.
mySQL has a native field type for dates:
DATE.Not sure what further explanation to give 🙂 If you want to store dates in a mySQL table,
DATEsimply is the one correct choice. It comes with optimized indexing for queries like>,<andBETWEEN, sorts fast, and can deal with any date from the years 1001-9999, so this really is the way to go.