Solved

How to perform date comparison in crystal report?

Posted on 2004-04-03
3
709 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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