Solved

How to perform date comparison in crystal report?

Posted on 2004-04-03
3
707 Views
Last Modified: 2012-08-14

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
Comment
Question by:capriono
3 Comments
 
LVL 2

Accepted Solution

by:
eric_duncan earned 20 total points
ID: 10754030
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question