Reputation: 21
I new to PHP and confused with date, time, datetime and timestamp. I have a MYSQL table contains date, time, datetime and timestamp.
Whats the format to use from PHP to MYSQL fields?
sql_timestamp = gmdate("Y-m-d H:i:s", time());
$date_conv = new DateTime($this->sql_timestamp);
sql_date = $date_conv->format('Y-m-d');
sql_time = $date_conv->format('H:i:s');
sql_datetime = gmdate("Y-m-d H:i:s", time()); ??? I am confused here
I dont see different between DATETIME and Timestamp assignment ? Could anyone help what i need to keep in these four fields? Thank you
Upvotes: 1
Views: 323
Reputation: 1703
Assuming you are asking about MySQL:
TIMESTAMP is, essentially, a DATETIME that is automatically converted to UTC when stored by MySQL and automatically adjusted for the timezone of specified to the MySQL connection. TIMESTAMP also has a smaller date storage range than DATETIME.
See the MySQL manual on this topic for more information.
Upvotes: 1