简体   繁体   中英

PHP MYSQL date, time, datetime and timestamp

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM