Solved

How to perform date comparison in crystal report?

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

21 Experts available now in Live!

Get 1:1 Help Now