MySQL DATE, DATETIME, and TIMESTAMP Tutorials

In MySQL, date and time can be stored using 3 types, DATE, DATETIME, and TIMESTAMP. They are related.

MySQL recognizes DATE, DATETIME, and TIMESTAMP values in several formats.

  • DATE type format: ‘YYYY-MM-DD’
  • DATETIME type format: ‘YYYY-MM-DD hh:mm:ss’
  • TIMESTAMP type format: a timestamp integer

Set default value as today or now

CREATE TABLE sale (
    `order_date`     DATETIME DEFAULT CURRENT_TIMESTAMP,
    `last_modified` DATETIME ON UPDATE CURRENT_TIMESTAMP,
    `confirm_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close