Print Page | Close Window

Date Comparison Formula

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=3723
Printed Date: 03 May 2024 at 10:55pm


Topic: Date Comparison Formula
Posted By: heme3
Subject: Date Comparison Formula
Date Posted: 16 Jul 2008 at 7:18am
I'm using CR8, the following formula gives me 3 date ranges based on the # of days in the "current period" (for example: current period 1 to 10 July 2008, prior period 22 Jun to 1 July 2008, and last year period 1 to 10 July 2007)
 
--------

({CRIMES_ALLV.DATEOCC} in dateadd("d",-(datediff("d",{?StartDate},{?EndDate})),{?StartDate})to{?StartDate}
or
{CRIMES_ALLV.DATEOCC} in dateadd("yyyy",-1,{?StartDate}) to Dateadd("yyyy",-1,{?EndDate})
or
{CRIMES_ALLV.DATEOCC} in {?StartDate} to{?EndDate})
 
--------

This part of the formula: ({CRIMES_ALLV.DATEOCC} in dateadd("d",-(datediff("d",{?StartDate},{?EndDate})),{?StartDate})to{?StartDate}

gives me the prior period 22 Jun to 1 July, but I need it to give me 21 Jun to 30 Jun (so that I'm not overlapping the 1 July date in my comparisons.

Any tips or clues out there?


-------------
heme3



Print Page | Close Window