04
Chapter 4
Date & Time Functions
Time, done properly. Intervals, truncation, extraction, time zones, and the arithmetic that survives DST.
In this chapter
16
queries, easy → advanced
- 001CURRENT_DATE, NOW(), CURRENT_TIMESTAMPRead
- 002Date arithmetic: add/subtract intervalsRead
- 003EXTRACT: get date partsRead
- 004DATE_TRUNC: truncate to time periodRead
- 005AGE: calculate time differenceRead
- 006TO_CHAR: format dates as stringsRead
- 007Generate series of dates for calendar queriesRead
- 008Time zone conversion and handlingRead
- 009Business days calculation (excluding weekends)Read
- 010Show orders from last 7 days, last 30 days, last 90 daysRead
- 011Show age of each customer accountRead
- 012Find the busiest day of week for ordersRead
- 013Calculate SLA breach: orders not shipped in 3 daysRead
- 014Find employees with work anniversaries this monthRead
- 015Calculate business hours between two timestampsRead
- 016Partition by date range with automatic partition creationRead