UNIX timestamp issue on MYSQL insert via PHP
Im receiving data with a created time field given in a unix timestamp format for example "1251324809" which to my understanding is the amount of time elapsed since the epoch, 1970.
Ive got a DATETIME formatted field in a MYSQL table, and im using this to return the UNIX time to a YY-MM-DD HH:MM:SS format:
date('Y-m-d H:i:s', $timestamp);
and then storing it in the database. The problem is some of my dates are bein开发者_如何学编程g stored accurately and some of them are being stored as 1970-01-01 02:00:00, its only a small percentage of the data but i need to know why? Am i perhaps receiving the data incorrectly sometimes?
Am i perhaps receiving the data incorrectly sometimes?
Probably. January 1st, 1970 points to $timestamp
being zero or a value that can't be parsed as a time stamp.
I find that dates in php and mysql never work properly. Particualrly as I am in a vastly different timezone than my server.
In mysql I avoid the problem by having the date fields stored as int(11)
I then insert the php calculated timestamp (usually via time()) into them.
精彩评论