Skip to Content
Former Member
Mar 21, 2012 at 03:12 PM

Formatting dates for selection in c#


I have the following code in my submit button to filter the data that is shown in the crystal report 2010/vs 2010 c#.

protected void Button_Submit_Click(object sender, EventArgs e)
DateTime startdate = Convert.ToDateTime(TextBox_StartDate.Text);
DateTime enddate = Convert.ToDateTime(TextBox_EndDate.Text);string factory = ddlFactory.SelectedValue;
string selectFormula = "{VW_MIXER_EMPTY_TIMES_ALL.FACTORY}=" + "'" + factory + "' and " + "{VW_MIXER_EMPTY_TIMES_ALL.DATETIME_DUMP} IN [" + "'" + startdate + "' TO " + "'" + enddate + "']";

crystalReportViewer.SelectionFormula = selectFormula;
crystalReportViewer.Visible = true;

This gives me the following error:

A date-time is required here. Details: errorKind
Error in File emptymixers {E2F90D89-36FB-4550-99C2-64409FED7E8B}.rpt: Error in
formula Record_Selection: '{VW_MIXER_EMPTY_TIMES_ALL.FACTORY}='01' and
'3/21/2012 6:00:00 AM']' A date-time is required here. Details: errorKind

The dates look formatted correctly, but or CR is not recognizing them as dates. I've tried searching this forum this morning and get an error every time saying my request can't be completed. So I'm starting a new discussion because I need to get this report working ths morning.

Thanks for any help or direction you can provide.