SQL & Databases Masterclass Course
Welcome to the ultimate postgresql tutorial for beginners 2026. Work through interactive sql practice problems with solutions, master our comprehensive sql window functions tutorial modules, and prepare for tough sql interview questions at Google and Amazon entirely in your browser. Claim your course completion XP and build production-ready database mastery today!
SQL Date Format: How to Work with Dates & Times
Introduction & Core Concept
Time-series tracking is the foundational backbone of financial auditing, user activity cohorts, and sales reporting. SQL provides powerful built-in date formatting functions to parse timelines and compute interval offsets.
In SQLite, we format and extract granular calendar components using strftime (String Format Time) and calculate interval modifications using the date function.
SELECT strftime('%Y-%m', order_date) AS month FROM orders;π‘ MSSQL Tip: Microsoft SQL Server (MSSQL) does not usestrftime. Instead, you useFORMAT()orDATEPART()! For example:SELECT FORMAT(order_date, 'yyyy-MM') FROM orders;
Core Date Format Modifiers
strftime('%Y', date_col) β Extracts the 4-digit Year.strftime('%m', date_col) β Extracts the 2-digit Month.strftime('%Y-%m', date_col) β Truncates timestamp to Year-Month level.date(date_col, '+30 days') β Calculates future calendar offsets.Why & Where We Use It
Real-World Example
ApexBank needs an auditing report grouping all retail bank transactions by Year-Month segments to evaluate monthly gross cash flow volumes across the enterprise.
Best Practices: What to Do & What NOT to Do
YYYY-MM-DD HH:MM:SS) in your database schemas to avoid confusing daylight savings time drift across international server regions.BETWEEN with raw dates without understanding midnight truncation rules. WHERE date BETWEEN '2026-05-01' AND '2026-05-05' cuts off at exactly 00:00:00 on May 5th, accidentally omitting transactions occurring later that day!Syntax & Pro Tips
SELECT strftime('%Y', created_at) AS join_year, COUNT(*)
FROM users GROUP BY join_year;