SQL CURRENT_DATE

Returns today's date — no time-of-day component, just the calendar date, straight from the database server.

What & Why

CURRENT_DATE returns the database transaction's calendar date and CURRENT_TIMESTAMP returns its timestamp. They are stable throughout one transaction.

The worked Queryflo result pins the teaching clock to March 20, 2024 so the displayed campaign rows stay reproducible. In a live report, replace those two literals with CURRENT_DATE and CURRENT_TIMESTAMP.

See How It Works

BUSINESS QUESTION

Using a fixed teaching clock, Marketing wants the campaigns active on 2024-03-20 and the report timestamp beside them.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
-- In a live report, replace these teaching values with CURRENT_DATE
-- and CURRENT_TIMESTAMP.
WITH report_clock AS (
  SELECT
    DATE '2024-03-20' AS current_date,
    TIMESTAMPTZ '2024-03-20 12:00:00+00' AS current_timestamp
)
SELECT
  c.name,
  c.start_date,
  c.end_date,
  clock.current_timestamp AS reported_at
FROM marketing.campaigns c
CROSS JOIN report_clock clock
WHERE c.start_date <= clock.current_date
  AND (c.end_date IS NULL OR c.end_date >= clock.current_date)
ORDER BY c.name;
RESULT — exact output from the displayed Queryflo rows
namestart_dateend_datereported_at
Finance Retargeting2024-03-122024-05-312024-03-20 12:00:00+00
Retention Webinar2024-02-102024-04-152024-03-20 12:00:00+00
Spring Launch2024-01-152024-03-312024-03-20 12:00:00+00

The fixed teaching clock makes the active-campaign result reproducible.

Now You Try

Practice this concept

Using the fixed March 20, 2024 teaching clock, return campaigns active that day and the fixed report timestamp, ordered by name.

Available schema
marketing

Prefix tables with marketing.table_name.

namestart_dateend_datereported_at
marketing.campaigns
ColumnType
idinteger
nametext
channeltext
spendnumeric
start_datedate
end_datedate
statustext
target_segmenttext
legacy_idtext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario