Introduction to Date and Time Functions
Learn about functions for date and time in MySQL.
We'll cover the following
MySQL supports five categories of data types: numeric, date and time, string, spatial, and JSON. For date and time, the database management system provides a variety of data types, i.e., DATE
, TIME
, DATETIME
, TIMESTAMP
, and YEAR
. The data type representing dates is DATE
with values representing 'YYYY-MM-DD'
. TIME
represents time as 'hhh:mm:ss'
where hhh
denotes hours, mm
represents minutes, and ss
stands for seconds. The data type representing a date associated with a time of the day in MySQL is DATETIME
. It is not exactly a combination of DATE
and TIME
but close. The format used to represent DATETIME
is 'YYYY-MM-DD hh:mm:ss'
. Similar to DATETIME
, TIMESTAMP
is the data type representing a date associated with a time of the day. However, TIMESTAMP
has a more constrained range and stores time with time zone information. Finally, MySQL provides the data type YEAR
with the display format YYYY
to represent a single year.
Get hands-on with 1400+ tech skills courses.