1

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

1
  • timestamp and datetime have the same format. There are some behavioral differences as pointed out in the answer by Jacob S below and the MySQL documentation. Commented Jun 19, 2013 at 15:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.