SELECT NOW(), CURRENT_DATE(), CURRENT_TIME();Useful for diagnostics, defaults, and test queries.
now, date_add, date_sub, date_format, timestampdiff, json_extract, json_set, json_object, concat, coalesce, and case in MySQL.
The most useful date arithmetic and formatting helpers.
SELECT NOW(), CURRENT_DATE(), CURRENT_TIME();Useful for diagnostics, defaults, and test queries.
SELECT DATE_ADD(NOW(), INTERVAL 7 DAY) AS one_week_from_now;Common in expiration, scheduling, and retention logic.
SELECT DATE_SUB(NOW(), INTERVAL 30 DAY) AS thirty_days_ago;Handy for rolling windows and recent-activity filters.
SELECT DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') AS created_at_fmt FROM orders LIMIT 5;Formatting is often better done in the app layer, but this is useful in reports and exports.
SELECT TIMESTAMPDIFF(MINUTE, created_at, NOW()) AS age_minutes FROM sessions;Useful for SLAs, queue age, and freshness calculations.
Practical JSON and text-processing examples for application data.
SELECT JSON_EXTRACT(settings, '$.notifications.email') AS email_enabled FROM user_preferences;Returns JSON data; use `->>`-style unquoting equivalents or JSON_UNQUOTE when needed.
UPDATE user_preferences
SET settings = JSON_SET(settings, '$.theme', 'dark')
WHERE user_id = 42;Useful for gradually evolving settings blobs without replacing the whole document manually.
SELECT JSON_OBJECT('id', id, 'email', email) AS user_json FROM users LIMIT 5;Helpful for API prototyping, exports, and SQL-side reshaping.
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM contacts;A basic but common formatting function.
SELECT COALESCE(display_name, full_name, email) AS label FROM users;Great for optional columns and layered display fallbacks.
SELECT id,
CASE status
WHEN 'paid' THEN 'Paid'
WHEN 'pending' THEN 'Pending'
ELSE 'Other'
END AS status_label
FROM orders;`CASE` is essential for SQL-side normalization and reporting.