SQL DatabaseLesson 61Free preview
SQL Dates
This lesson is part of SQL · All levels
Summary
MySQL has specific data types for dates and times, including DATE, TIME, DATETIME, TIMESTAMP, and YEAR. Built-in functions such as NOW, CURDATE, and DATE_FORMAT help to obtain and format date values. It is important to pay attention to the format YYYY-MM-DD to ensure that the date comparison is correct.
Key points
- Data types: DATE for dates only, DATETIME, TIMESTAMP, TIME, and year.
- Common functions: NOW(), CURDATE(), CURTIME(), DATE(), YEAR(), DATE_FORMAT().
- The default date format of MySQL is YYYY-MM-DD.
- TIMESTAMP is sensitive to the server time zone, whereas DATETIME retains its value.
- In the DATETIME column, use the DATE() function so that the clock component does not interfere with the comparison.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.