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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use data from previous year

Status
Not open for further replies.

kwirky

MIS
Apr 22, 2010
85
AU
Hi,
Am trying to figure out a formula/s to show me the date of the previous year, based on day of the week and week number.
Say yesterday is Wednesday 1st June. I want to find out the DATE for Wednesday LAST YEAR. I know that this date is 2/6/2010 by checking a calendar.
So what I want is for an automatic calculation based on the week number and then the day number.
So far I have the following (but have not figured out how to tie them together to get the date):
@previousyear
date(year(currentdatetime)-1,month(currentdatetime),day(currentdatetime)-1)

@weeknumber
DatePart ("ww", {@PreviousYear})

I tried this, which I got from Ken Harmady website, but it gives me the date of 7th of June 2010 and no matter what I do to it, I cannot get it to say 2nd June 2010:

WhileReadingRecords;
DateVar target := Date (2010,1,1);
if DayOfWeek (target) in 2 to 5
then target:= target - 7 * ({@weeknumber}-1)
else target:= target + 7 * ({@weeknumber}) ;

target - DayOfWeek (target) + {@dayofweek}



I am using CR2008 & SQL database
 
See if the following meets your needs:

WhileReadingRecords;
numbervar wk := datepart("ww",currentdate)-1;
DateVar target := Date(year(currentdate)-1,1,1);
target - DayOfWeek (target) + dayofweek(currentdate)

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top