I was thinking of using TIMESTAMP to store the date+time, but I read that there is a limitation of year 2038 on it. Instead of asking my question in bulk, I preferred to bre
When using UNIX Timestamps to store dates, you are actually using a 32 bits integers, that keeps count of the number of seconds since 1970-01-01 ; see Unix Time
That 32 bits number will overflow in 2038. That's the 2038 problem.
To solve that problem, you must not use a 32 bits UNIX timestamp to store your dates -- which means, when using MySQL, you should not use TIMESTAMP
, but DATETIME
(see 10.3.1. The DATETIME, DATE, and TIMESTAMP Types) :
The
DATETIME
type is used when you need values that contain both date and time information. The supported range is'1000-01-01 00:00:00'
to'9999-12-31 23:59:59'
.The
TIMESTAMP
data type has a range of'1970-01-01 00:00:01'
UTC to'2038-01-19 03:14:07'
UTC.
The (probably) best thing you can do to your application to avoid/fix that problem is to not use TIMESTAMP
, but DATETIME
for the columns that have to contain dates that are not between 1970 and 2038.
One small note, though : there is a very high probably (statistically speaking) that your application will have been re-written quite a couple of times before 2038 ^^ So maybe, if you don't have to deal with dates in the future, you won't have to take care of that problem with the current version of your application...