MySQL DatabaseLesson 61Free preview
MySQL Dates
This lesson is part of MySQL · All levels
Summary
MySQL provides data types DATE, TIME, DATETIME, TIMESTAMP, and YEAR to store time, complete with built-in functionality to take, format, and compare dates. Functions such as NOW(), CURDATE(), DATE_FORMAT(), and DATEDIFF facilitate the manipulation of temporal data. Note the difference between the TIMESTAMP stored in UTC and the DATETIME that keeps the value as it is.
Key points
- DATE stores the date (2025-06-17), DATETIME and TIMESTAMP store the date plus the hour
- TIMESTAMP is stored in UTC and converted to the server time zone, DATETIME is not
- It takes time now, only dates, only hours.
- DATE_FORMAT() displays the date according to the pattern, STR_TO_DATE() converts the string to the date
- DATEDIFF() calculates the difference in days, DATE_ADD/DATE_SUB adds or decreases time
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.