Skip to main content
A newer version of this page is available. .

Date Range Parameters

  • 4 minutes to read

This document describes how to create a date range parameter and filter report data by the specified dates.

Design Time

Perform the steps below to add a date range parameter to a report.

  1. Switch to the Field List and right-click Parameters. Select Add Parameter from the context menu.

    add-parameter

  2. Specify the options below in the invoked Add New Parameter dialog and click OK.

    • Name - the parameter’s name;
    • Description - the parameter’s description displayed to users;
    • Type - the parameter’s data type. Set it to Date to create a date range;
    • Range Value - enable this option to create a date range.

    add-parameter-dialog

  3. The dateRange parameter appears in the Field List and includes the inner dateRange_Start and dateRange_End parameters. Select the dateRange parameter and switch to the Property Grid to specify the inner parameters’ default values.

    configure-subparam

    The Value property allows you to specify a static default value. Use the ValueExpression property to specify a dynamic default value. Click the ValueExpression‘s ellipsis button and specify an expression in the invoked Expression Editor.

    value-expression

  4. Use the start and end parameter names in the report’s FilterString to filter data by the created date range. Select the report, click the FilterString‘s ellipsis button in the Property Grid and construct the filter string in the invoked FilterString Editor.

    filterstring

    Note

    The start and end parameter values store the selected day’s midnight time. For instance, if a user chooses 10/15/2019, the DateTime value is 10/15/2019 12:00:00 AM. If your date fields include non-midnight time, records for the end date 10/15/2019 are excluded from a report. Use the GetDate() function in the FilterString Editor to include data for the 10/15/2019 date.
    filterstring

When users switch to Print Preview, the Parameters panel displays the date range parameter. After a user submits a start and end date, a report document is displayed with filtered data.

Runtime

The code sample below illustrates how to create a date range parameter in a report, and to filter report data by the specified date range.

using DevExpress.XtraReports.Parameters;
using DevExpress.XtraReports.Expressions;
// ...
XtraReport1 report = new XtraReport1();

// Create a date range parameter.
Parameter myDateRange = new Parameter();
myDateRange.Name = "myDateRange";
myDateRange.Description = "Date Range:";
myDateRange.Type = typeof(System.DateTime);
RangeParametersSettings myDateRangeSettings = new RangeParametersSettings();

// Specify the start date and end date's default values.
myDateRangeSettings.StartParameter.Name = "MyDateRangeStart";
myDateRangeSettings.StartParameter.ExpressionBindings.Add(new BasicExpressionBinding("Value", "AddDays(Today(), -7)"));
myDateRangeSettings.EndParameter.Name = "MyDateRangeEnd";
myDateRangeSettings.EndParameter.ExpressionBindings.Add(new BasicExpressionBinding("Value", "Today()"));
myDateRange.ValueSourceSettings = myDateRangeSettings;
report.Parameters.Add(myDateRange);

// Filter report data by the specified date range.
report.FilterString = "GetDate([OrderDate]) Between(?MyDateRangeStart,?MyDateRangeEnd)";

Related API

Parameter Class

Parameter.ValueSourceSettings Property

RangeParametersSettings Class

Customize Predefined Ranges

You can customize the set of predefined date ranges. This set is stored in the RangeParameterEditorOptions static class and is available in all date range parameter editors when they are displayed in Print Preview.

sample-expanded

Note

This code is in effect for WinForms and WPF End-User Reporting Applications only.

using DevExpress.XtraReports.Parameters;
using DevExpress.XtraReports.Expressions;
// ...
// Remove all predefined ranges and add two new date ranges.
RangeParameterEditorOptions.PredefinedDateRanges.Clear();
RangeParameterEditorOptions.RegisterDateRange("September", () => new DateTime(2019,9,1), () => new DateTime(2019,9,30));
RangeParameterEditorOptions.RegisterDateRange("October", () => new DateTime(2019,10,1), () => new DateTime(2019,10,31));