1. Home
  2. /
  3. Docs
  4. /
  5. Articles Report Writer
  6. /
  7. Dialog Components
  8. /
  9. Date Range Picker Dialog ...

Date Range Picker Dialog Control

The Date Range Picker control provides a pair of date editors — Start Date and End Date — with a row of navigation buttons for quickly setting common date ranges. It is designed for use on report dialog pages where the user needs to specify a date range before the report runs.

Selected dates are automatically written to report variables and survive the FastReport component rebuild that occurs between the dialog and report phases, so the values are always available in BeforeStartReport and throughout the report.


Adding to a Report

Drop a Date Range Picker onto a dialog page. The control arrives with a default width of 560 and a height of 96 (70 if quarter buttons are hidden). No dataset connection is needed — it works standalone.

The selected dates are stored in two report variables named after the control:

<ControlName>.StartDate
<ControlName>.EndDate

For example, if the control is named DateRangePicker1, the variables are DateRangePicker1.StartDate and DateRangePicker1.EndDate. These can be used directly in report expressions or read from script.


The control includes two rows of quick-navigation buttons. Each button operates on whichever date editor currently has focus — Start Date or End Date — unless noted otherwise.

Row 1 — Date navigation

ButtonAction
– 30 daysSubtracts 30 days from the focused date
– 1 yearSubtracts 1 year from the focused date
TodaySets both Start Date and End Date to today
+ 30 daysAdds 30 days to the focused date
+ 1 yearAdds 1 year to the focused date
FDMSets the focused date to the first day of its month
LDMSets the focused date to the last day of its month

Row 2 — Quarter buttons

ButtonAction
Q1Sets the range to Q1 (Jan 1 – Mar 31) of the focused date’s year
Q2Sets the range to Q2 (Apr 1 – Jun 30) of the focused date’s year
Q3Sets the range to Q3 (Jul 1 – Sep 30) of the focused date’s year
Q4Sets the range to Q4 (Oct 1 – Dec 31) of the focused date’s year

Properties

PropertyTypeDefaultDescription
StartDateTDateTodayThe currently selected start date. Read or set from script.
EndDateTDateTodayThe currently selected end date. Read or set from script.
ShowTodayButtonBooleanTrueShows or hides the Today button
ShowDayButtonsBooleanTrueShows or hides the ±30 days buttons
ShowYearButtonsBooleanTrueShows or hides the ±1 year buttons
ShowFirstLastButtonsBooleanTrueShows or hides the FDM and LDM buttons
ShowQuarterButtonsBooleanTrueShows or hides the Q1–Q4 row. Hiding this also reduces the control height from 96 to 70.

Script Methods

MethodDescription
SetRange(AStart, AEnd: TDateTime)Sets both dates at once. Raises an exception if AStart is after AEnd.
SetQuarter(AQuarter, AYear: Integer)Sets the range to a specific quarter (1–4) of a specific year.
GetStartDate: TDateTimeReturns the current start date
GetEndDate: TDateTimeReturns the current end date

Events

EventDescription
OnClickFires when the control is clicked
OnEnterFires when focus enters the control
OnExitFires when focus leaves the control
OnKeyDownFires when a key is pressed down
OnKeyPressFires when a key is pressed
OnKeyUpFires when a key is released
OnMouseDownFires when a mouse button is pressed
OnMouseMoveFires when the mouse moves over the control
OnMouseUpFires when a mouse button is released

Report Variables

The control automatically writes its selected dates to report variables each time either date changes. These variables survive the FastReport component rebuild between the dialog and report phases and are available throughout the report.

VariableTypeDescription
<Name>.StartDateTDateTimeThe selected start date (date portion only, no time)
<Name>.EndDateTDateTimeThe selected end date (date portion only, no time)

Use them directly in report text object expressions:

[FormatDateSafe(DateRangePicker1.StartDate, 'mm/dd/yyyy')]
[FormatDateSafe(DateRangePicker1.EndDate, 'mm/dd/yyyy')]

Validation

The control validates that Start Date is never after End Date. If the user types or navigates to an invalid combination:

  • If Start Date is edited and the result would be after End Date, the value is reverted when the editor loses focus
  • If End Date is edited and the result would be before Start Date, the value is reverted when the editor loses focus
  • If the user clicks OK without tabbing out of an editor, the dialog captures and validates the final values before closing. If Start Date is after End Date at that point, the dates are automatically swapped.

Examples

Reading the selected dates in BeforeStartReport

procedure BeforeStartReport;
begin
  SetParam('qrySales', 'StartDate', DateRangePicker1.StartDate);
  SetParam('qrySales', 'EndDate',   DateRangePicker1.EndDate);
end;

Using dates directly in a report expression

// In a report title text object
Sales Report: [FormatDateSafe(DateRangePicker1.StartDate, 'mm/dd/yyyy')]
           to [FormatDateSafe(DateRangePicker1.EndDate,   'mm/dd/yyyy')]

Setting a default date range from script

// Default to the current month in BeforeStartReport or OnDialogShow
var y, m, d: Word;
DecodeDate(Date, y, m, d);
DateRangePicker1.SetRange(
  EncodeDate(y, m, 1),
  EndOfTheMonth(Date)
);

Setting a specific quarter

// Set the range to Q1 of the current year
var y, m, d: Word;
DecodeDate(Date, y, m, d);
DateRangePicker1.SetQuarter(1, y);

// Set the range to Q3 of 2024
DateRangePicker1.SetQuarter(3, 2024);

Setting a rolling 30-day window

// Last 30 days up to and including today
DateRangePicker1.SetRange(Date - 30, Date);

Using Sage 50 period dates

// Set the range to the current Sage 50 accounting period
DateRangePicker1.SetRange(
  SagePeriodStartDate([ConnectionDef], [Param.Period]),
  SagePeriodEndDate([ConnectionDef],   [Param.Period])
);

Hiding buttons you don’t need

// Minimal UI — just the date editors and Today button
DateRangePicker1.ShowDayButtons       := False;
DateRangePicker1.ShowYearButtons      := False;
DateRangePicker1.ShowFirstLastButtons := False;
DateRangePicker1.ShowQuarterButtons   := False;
// Control height automatically reduces to 70 when quarters are hidden

Combining with a DB Lookup for filtered reporting

procedure BeforeStartReport;
begin
  // Apply both the customer selection and the date range
  SetParam('qryOrders', 'CustomerID', DBLookupExtended1.KeyValue);
  SetParam('qryOrders', 'StartDate',  DateRangePicker1.StartDate);
  SetParam('qryOrders', 'EndDate',    DateRangePicker1.EndDate);
end;