Date and Time Literals — SQL Technical Interview Questions & Answers
Date and Time Literals
Date and Time Literals
- Date and Time Literals (DATE_AND_TIME_LITERALS) is a MySQL date/time helper. Dates are stored in DATE / DATETIME / TIMESTAMP columns. Always quote literals: '2026-08-19'.
- Typical pattern: SELECT DATE_AND_TIME_LITERALS(…); or SELECT DATE_AND_TIME_LITERALS(dob) FROM students; NOW() / CURDATE() / CURTIME() have empty brackets — they read the clock.
- DATE_FORMAT(dob, '%d-%b-%Y') is for display. DATEDIFF(end, start) is days between. INTERVAL 7 DAY is how you add a week: DATE_ADD(CURDATE(), INTERVAL 7 DAY).
- Trap: comparing dates as VARCHAR. Trap: TIMESTAMP vs DATETIME timezone stories — DATETIME is ‘wall clock’, TIMESTAMP is UTC-stored (say this only if asked).
- On the example next to this theory: Date and Time Literals — wHERE combines predicates with AND/OR; LIKE does pattern match.
Technical Interview Tip: DATE_AND_TIME_LITERALS: one SELECT example. Quote 'YYYY-MM-DD'.
Code Examples for Date and Time Literals
Date and Time Literals — sample query
CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT, price REAL);
INSERT INTO products VALUES (1, 'Pen', 10), (2, 'Book', 200), (3, 'Bag', 50);
SELECT * FROM products
WHERE price BETWEEN 20 AND 150 AND name LIKE 'B%';Date and Time Literals — wHERE combines predicates with AND/OR; LIKE does pattern match.
How to Explain Date and Time Literals to an Interviewer
What is DATE_AND_TIME_LITERALS?
Date/time function for Date and Time Literals Use in SELECT on a DATE column
Current datetime?
NOW() or CURRENT_TIMESTAMP