0

If I generate a timestamp with PHP's time() and insert/update a row with it, what column type should I use?

I've used varchar(20) (64-bit) in the past, and I tried TIMESTAMP just then and it has the year 2038 error it seems.

Is it okay to just use varchar(20) to store a timestamp?

frosty
  • 2,779
  • 6
  • 34
  • 63

2 Answers2

0

use DATETIME datatype,

MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' .

The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

you may also go through this,

PHP & mySQL: Year 2038 Bug: What is it? How to solve it?

Community
  • 1
  • 1
Hytool
  • 1,358
  • 1
  • 7
  • 22
0

Use DATETIME as datatype and use date('Y-m-d H:i:s') with the time as optional parameter to insert into the column. See http://de.php.net/manual/en/function.date.php for more info on the date function.

Splatbang
  • 756
  • 1
  • 12
  • 29