Print Page | Close Window

Date Minus a Year

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Tips and Tricks
Forum Discription: Have you learned some great tricks to share with the group? Post them here!
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=15476
Printed Date: 28 Apr 2024 at 10:07am


Topic: Date Minus a Year
Posted By: Em123
Subject: Date Minus a Year
Date Posted: 29 Jan 2012 at 12:19am
I am trying to compare transaction data between previous years and the current year. I am using tdate as the transaction date and I have two parameters called Start Date and End Date. How do I assign the following. (Using Crystal Syntax)
 
Start Date>= tdate - 1 year and End Date<= tdate - 1 year
 
The transaction data needs to be shown in two columns one for this year one for last year showing the sum per day. I will eventually either use a cross tab or possibly a group to do each day but need them split per year as well.
 
If possible I would like to match the day of this year to the same day of last year. E.g. Sunday 29th Jan 2012 would match up with Sunday 30th Jan 2012.
 
Any ideas much appreciated! Smile



Replies:
Posted By: rkrowland
Date Posted: 29 Jan 2012 at 9:50pm

{?startdate} >= dateadd("yyyy",-1,{tdate})
and
{?enddate} <= dateadd("yyyy",-1,{tdate})
 
would replicate the formula above.
 

{?startdate} >= dateadd("ww",-52,{tdate})
and
{?enddate} <= dateadd("ww",-52,{tdate})
 
Would return the same day of the week a year ago.
 
 
However I assume your startdate occurs before your enddate? The above formulas wouldn't return any entries as you're asking for a return where the transaction date is before the startdate and after the enddate.
 
dateadd("ww",-52,{tdate})  >= {?startdate} 
and
dateadd("ww",-52,{tdate}) <= {?enddate}
 
Would return everything between the start and end date.
 
Regards,
Ryan.



Print Page | Close Window