SAP Knowledge Base Article - Public

1206240 - How to set the default value of a date parameter to the current date in Crystal Reports?

Symptom

  • How to set the date parameter default value to the current date?
  • How to set today's date, as the default value for a date parameter in Crystal Reports?

Environment

  • SAP Crystal Reports 2013
  • SAP Crystal Reports 2016
  • SAP Crystal Reports 2020

Reproducing the Issue

  1. In Crystal Reports, create a report off any data source.
  2. Add a date parameter to the report.
  3. When refreshing the report, the date parameter value is either blank.
        
    How to set the default value to today's date?

Cause

  • There is unfortunately no option in Crystal Reports to set the date parameter default value to today's date.

Resolution

  • To workaround this situation, set the default date parameter to a specific default value, and create a Record Selection to returns today's data, if the parameter is equal to this specific date value.
          
    1. In Crystal Reports designer, modify the date parameter, and set the default value in the date or datetime parameters to a date that will never appear in the data. (For example, 1900-01-01)
            
    2. Add to the Record Selection Formula of the report, a condition that returns today's date data if the parameter is equal to the default date value.
      The Record Selection Formula will be like:
         
          If {?DateParameter} = Date(1900,1,1) Then
                {My Date Database Field} = DataDate
          Else 
                {My Date Database Field} = {?DateParameter}

      Note: The function DataDate, returns today's date when a report is refreshed.
              
    3. Now, when refreshing the report, if no value is entered for the date parameter, it will return the data for the current date on the report.

Keywords

CR, Today's date, currentdate , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

SAP Crystal Reports 2013 ; SAP Crystal Reports 2016 ; SAP Crystal Reports 2020