Time is the most common dimension in analytics — sales by month, growth year-over-year, average delivery days. MySQL's date functions make these calculations straightforward once you know the toolbox.
Key Points
- Current values: NOW() (datetime), CURDATE() (date), CURTIME() (time)
- Format for reports: DATE_FORMAT(order_date, '%b %Y') → 'Jul 2026'
- Differences: DATEDIFF(delivered_at, ordered_at) returns days
- Arithmetic: DATE_ADD(NOW(), INTERVAL 30 DAY), DATE_SUB for the past
- Extract parts: YEAR(), MONTH(), QUARTER(), DAYNAME()
- Group by month: GROUP BY DATE_FORMAT(order_date, '%Y-%m')
.png)