Contact Our Development Team
Free Code Tutorials & Open Source Code
MySQL - Dates & Times
Tutorials > MySQL > Dates & Times
Dates and Times in MySQL
One of the most common data types you will need to store, after strings and integers, is dates and times. Knowing when things have happened is hugely important, so MySQL provides a number of different formats for storing dates and times, depending on the range and precision you need. Here's an overview of the types:
YEAR
Stores a year in the format YYYY, in the range 1901 to 2155.
DATE
Stores a date in the format YYYY-MM-DD, in the range 1000-01-01 to 9999-12-31.
DATETIME
Stores a date and time in the format YYYY-MM-DD HH:mm:ss, in the range 1000-01-01 00:00:00 to 9999-12-31 23:59:59.
TIMESTAMP
Stores a timestamp in the format YYYY-MM-DD HH:mm:ss, in the range 1970-01-01 00:00:00 to 2037-12-31 23:59:59. Although this date range appears to be the limit of 32-bit UNIX timestamps, the TIMESTAMP field in MySQL is not always stored as a UNIX timestamp, and is often undergoing revision (possibly to prepare for 64-bit UNIX timestamps). We would recommend using DATETIME unless you need fast indexing on your time columns.
Page Responses
Currently there have been no responses to this page...
If you have anything to contribute to this tutorial, found a bug, or know a better way of achieving the same goal, please leave your response below.
     
Copyright ©2009, Wired IDS Ltd. | Licensed under Creative Commons Attribution Share-Alike | Load time: 0.3109 seconds