Date/Time Functions Deep Dive
Date/Time Functions Deep Dive — Advanced date and time manipulation — NOW, EXTRACT, DATEADD, DATEDIFF, formatting, and time zones. The guide walks through Current Date & Time, EXTRACT() & Date Parts, Adding & Subtracting Intervals, Date Difference Calculations, Date Formatting, Time Zone Handling. NOW()/CURRENT_TIMESTAMP returns both date and time. CURRENT_DATE returns just the date. CURRENT_TIME returns just the time (not available in all databases). SYSDATE (Oracle/MySQL) returns the current timestamp. PostgreSQL: NOW() is equivalent to CURRENT_TIMESTAMP. CLOCK_TIMESTAMP() returns actual current time, while NOW() returns the transaction start time. EXTRACT(field FROM date) retrieves a specific component: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, DOW (day of week), DOY (day of year), QUARTER. PostgreSQL: EXTRACT(DOW FROM NOW()) returns 0 for Sunday. MySQL: EXTRACT(YEAR FROM hire_date). Alternative: DATEPART (SQL Server), TO_CHAR with format (Oracle/PostgreSQL). Use EXTRACT for grouping by date parts in reports. The guide is organized into 6 sections that build on each other, each pairing a prose explanation with real SQL you can run as-is.