Physical Address
Haryana ,India
Physical Address
Haryana ,India
Working with dates and times is a core part of data analysis. Numerous built-in functions in SQL facilitate the extraction, manipulation, and computation of date and time variables. Let’s go through the most useful Date and Time Functions one by one with clear examples.
SELECT NOW();
-- Output: 2025-08-17 14:25:36
This gives both the date and the time at the moment of query execution.
SELECT CURDATE();
-- Output: 2025-08-17
SELECT CURTIME();
-- Output: 14:25:36
SELECT DATE('2025-08-17 14:25:36');
-- Output: 2025-08-17
SELECT TIME('2025-08-17 14:25:36');
-- Output: 14:25:36
SELECT YEAR('2025-08-17');
-- Output: 2025
SELECT MONTH('2025-08-17');
-- Output: 8
SELECT DAY('2025-08-17');
-- Output: 17
SELECT DATE_ADD('2025-08-17', INTERVAL 10 DAY);
-- Output: 2025-08-27
SELECT DATE_SUB('2025-08-17', INTERVAL 5 DAY);
-- Output: 2025-08-12
SELECT TIMESTAMPDIFF(DAY, '2025-08-01', '2025-08-17');
-- Output: 16
SELECT EXTRACT(YEAR FROM '2025-08-17');
-- Output: 2025
SELECT EXTRACT(MONTH FROM '2025-08-17');
-- Output: 8
Mastering these SQL Date and Time functions will help you work faster and smarter with time-based data.