Solved

How to perform date comparison in crystal report?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

862 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now