Skip to content

Instantly share code, notes, and snippets.

@jaygaha
Created November 24, 2023 07:52
Show Gist options
  • Save jaygaha/e3b3283a4ebf09c618a824b2e5172683 to your computer and use it in GitHub Desktop.
Save jaygaha/e3b3283a4ebf09c618a824b2e5172683 to your computer and use it in GitHub Desktop.
mysql, data-type, timestampvsdatetime

MySQL timestamp vs datetime

Both TIMESTAMP and DATETIME store date and time information, but they have some differences in terms of the range they support and the way they handle time zones.

Here are a few things to consider:

  1. Range of Values:
    • TIMESTAMP: The range is '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
    • DATETIME: The range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
  2. Time Zone Handling:
    • TIMESTAMP: Automatically converts the time value to the current time zone for storage and retrieves it in the current time zone.
    • DATETIME: Does not have automatic time zone conversion. The time value is stored as provided.
  3. Existing Data:
    • When you change the data type from TIMESTAMP to DATETIME & vice-versa, the data should be compatible, and the conversion should be seamless. MySQL will perform the necessary conversion without losing data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment