Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WeektoDate and Last Year WeektoDate

Status
Not open for further replies.

ajoyp2

MIS
Apr 25, 2007
8
0
0
US
I need help with a formula for WeektoDate and Last Year weektoDate.The Weektodate in fact is last 7 days data depending on which day the Report is run.I need to do a comparison with same date range for last year in a subreport . I tried Dateadd formula but couldn't the correct data for Last Year's Report .I am on Crystal XI.
Any help would be appreciated.
 
To get the same dates, use formulas of:

dateserial(year(minimum(weektodate))-1,month(minimum(weektodate)),day(minimum(weektodate)))

dateserial(year(maximum(weektodate))-1,month(maximum(weektodate)),day(maximum(weektodate)))

Now link the subreport date to these fields. Then go intot he subreport's Report->Selection Formula->Record and change the = to >= and <= respectively.

You might have some difficulties in general if the mninimum or maximum happens to hit a leap year, so I suppose coding around that might be in order, you might want to test, but in that instance the above is still applicab le, you just test the dates created and adjust accordingly.

-k
 
Ooops, just realized that there isn't a weektodate in CR, I blindly followed your lead...

<sheepish grin>

What day do you wish to start the week with?

Here's formulas for Sunday, replace currentdate with your date:

// @startdate
whileprintingrecords;
numbervar wk := datepart("ww",currentdate);
numbervar dy := dayofweek(currentdate);
datevar startdt := currentdate - (dy-1);
dateserial(year(Startdt))-1,month(Startdt),day(Startdt))

// @enddate
evaluateafter ({@startdate});
startdt+6

-k
 
Well, there is WeektoDateFromSun.

-LB
 
Ahhh, should have used that, LB, tahnks, the first formula would work fine.

Been doing too much SQL programming lately, can't recall my lesser used Crystal syntax.

-k
 
Thanks for your help , I got the date range I was looking for through this formula :

{CHG_Change.Actual_End_Date})in Dateserial( (Year (CurrentDate)-1 ), Month (CurrentDate),day (Currentdate)) to Dateserial( (Year (CurrentDate)-1 ), Month (CurrentDate),day (Currentdate) -7)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top