What field do I use to store a timestamp in mysql?

Asked

Viewed 271 times

0

I need to store a timestamp with php, only I don’t know what would be the best field of mysql to use.

2 answers

2

Mysql has a type of TIMESTAMP, which is precisely UNIX TIMESTAMP, as it is mentioned here. Another option is to use INT, since it is an integer as well.

  • I have the feeling that you need to indicate a bit size when storing Unix timestamp. I don’t remember it being true, but it’s a strong feeling.

0


It depends what you need to store, if it is only the date you can use the DATE type, if it is only the TIME time and if it is both uses DATETIME. Just select which one the column will receive.

  • I wanted to store a timestamp with php’s time() function

  • If you want to record time, date or both current uses now() for example Insert into table(data) values (now()); but if you want a specific date I suggest you use the Date() function; Example $data = "20-01-2018";$dt = date(’d/m/Y', strtotime($data[0]));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.