Answer the question
In order to leave comments, you need to log in
Which field type to choose in mysql to save time from PHP?
Guys, please tell me, timestamp and datetime, as I understand it, for the time that is saved through now () (and I understand UTC as I understand it), but my time is saved through PHP with def. time zone, i.e. does not match the server. Do I understand correctly that in this case another type of field is already needed? Which one to choose, so that later it would be convenient to make a selection by time? So-so, of course, the question is, it’s just that all hands don’t reach the databases normally to make friends ((
Answer the question
In order to leave comments, you need to log in
No, not necessarily through NOW(), you can insert your own date and time value into the fields of the timestamp and datetime types, or you can choose one of the ready-made functions: NOW(), UTC_DATE(), etc.
timestamp takes 4 bytes in the base, and datetime 8 bytes, because 2 times more. Maria correctly noted that if you write data through NOW (), then the server time will be set, and if through a variable, then exactly the time that was in the variable will be set, regardless of all other factors (well, in the php settings, the time zone can also be adjusted).
In practice, IMHO datetime is somewhat easier to manipulate in the application, and if there is not a lot of data, then you can not think about bytes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question