When implementing CRUD, there is a problem in converting the date back and forth, because the user's view is dd.mm.yyyy , and the MySQL view is yyyy-mm-dd . Can MySQL store DATE as dd.mm.yyyy ?
4 answers
But what if you save the date in the muscle as a varchar? :) All restrictions are lifted .. really lost goodies muscular functions for working with dates .. But maybe you do not need it at all ..)
Save - no. But you can get output in a convenient format.
SELECT DATE_FORMAT("2011-11-08",'%d.%m.%Y'); result
08.11.2011 - Well, I know the question in another to remove from the script the duties on transformations. Is it possible to force mysql to do automatic conversions with a date? Stores let him as he pleases. And then what is the point of the database if it stores data as she wants? - culebre
Yes, you can store in any form, by the way in the INT format, storing the date is much easier and working with it. albeit a little need to convert, but more convenient and faster.
- Is it possible to transform directly into muscle? - culebre
- there is no when the muscle took the data in INT them in php let's say you convert it into the format you need. Something like timestamp only weighs less in the database. - Artem
It is best to store in datetime, in standard mysql format. When you receive data from the database - perform the conversion using date () to the desired form. When you save - perform the inverse transformation. Significantly speed will not lower this method, but all the possibilities of working with dates in the database will remain. Another option is to store the timestamp in INT, but again, a conversion is needed, and the possibility of working with the date in mysql is lost.