Would you recommend using a datetime or a timestamp field, and why (using MySQL)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Timestamps in MySQL are generally used to track changes to records, and are often updated every time the record is changed. If you want to store a specific value you should use a datetime field.
If you meant that you want to decide between using a UNIX timestamp or a native MySQL datetime field, go with the native
DATETIMEformat. You can do calculations within MySQL that way("SELECT DATE_ADD(my_datetime, INTERVAL 1 DAY)")and it is simple to change the format of the value to a UNIX timestamp("SELECT UNIX_TIMESTAMP(my_datetime)")when you query the record if you want to operate on it with PHP.Also, as of MySQL 8.0.19 the
DATETIMEsupports time zone offsets, so there’s even less reason to useTIMESTAMPnow.