Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 762
  • Last Modified:

How to perform date comparison in crystal report?


how to compare dates in crystal reports' selection formula.

I want to apply selection criteria on my crystal report.
Report is binded to a data view.
and i m doing like this

  CRViewer.SelectionFormula = "{v_advances.creationDate} > '2/2/2004'";

v_advances= database view name
creationDate= view's field's alias name

and its not working.

kindly tell me; how to compare dates in selection formula of crystal report.

0
capriono
Asked:
capriono
1 Solution
 
eric_duncanCommented:
In Crystal Reports you can't compare a date string to a date datatype - you have to convert the string to a Date first using the Date(year,month,day) function:

  CRViewer.SelectionFormula = "{v_advances.creationDate} > Date(2004,2,2)";

If you are trying to set the date dynamically in code you and you don't know for certain what the date is going to be beforehand, you could either parse the string to find the year, month, and day, or you could just do this:

  DateTime dt= DateTime.Parse('2/2/2004');
  CRViewer.SelectionFormula = String.Format("{{v_advances.creationDate}} > Date({0},{1},{2})",dt.Year,dt.Month,dt.Day);

Note that you have to escape the brackets around v_advances.creationDate per the requirements of the .Format function (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclassformattopic.asp).

Hope this helps!

Eric
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now