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!

Date period based on week number

Status
Not open for further replies.

kwirky

MIS
Apr 22, 2010
85
AU
Hi,
Can anyone assist with a formula which will give me dates based on what week number it is? (CR 2008)

I am able to get the week number using
DatePart ("ww", currentdate)

What I need is to have the date range from the Monday to the Saturday for the previous week. So if last week is week number 29, I get the dates 11/7/2011 to 16/7/2011.

I want to be able to get the data for the previous year based on the week number. So week number 29 LAST YEAR gives me the dates 12/7/2010 to 17/7/2010.

I have a main report with a subreport for the previous years' data.

Your help would be greatly appreciated :)
 
You have to specify these conditions in the datepart function if you are using anything other than the default:

datepart("ww",currentdate,firstdayofweek,firstweekofyear)

Look in the help section to understand the firstweekofyear constants. For firstdayofweek, you can use the dayofweek number, 7 for Saturday.

Note that it is unlikely that the same week the previous year will have the same day numbers, as you show in your example, so you need to clarify whether this is what you want, or whether you want the corresponding week.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top