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

Week Date

Status
Not open for further replies.

brishanny

MIS
Oct 3, 2003
17
US
If I have the week of a year- lets say week 15 of year 2004, can I get a date ranges like August 20 - August 26 from that?

Thanks
 
You can use the DateAdd function, you just need a starting date.
Try this:
@Add Weeks
Code:
whileprintingrecords;
numberVar weeknum := 15; //replace with your weeknum
datevar startdate := CDate(2004,1,4); //replace with your date

ToText(DateAdd("ww",weeknum,startdate),"MMMM dd") + " - " + 
ToText((DateAdd("ww",weeknum,startdate)+7),"MMMM dd");
I am using the first Sunday of 2004 as my start date, and 15 as my week number. It will return "April 18 - April 25".

~Brian
 
I was just about ready to post, when I saw that Brian did. This is just a slight variation. If you want a text display of the dates related to the weeknumber, use:

totext(dateadd("ww",{@weeknumber}-1,
Date(year({table.date}),01,01))-
dayofweek(Date(year({table.date}),01,01))+1,"MMMM d, yyyy") + " - "+
totext(dateadd("ww",{@weeknumber}-1,
Date(year({table.date}),01,01))-
dayofweek(Date(year({table.date}),01,01))+7,"MMMM d, yyyy")

//where {@weeknumber} =
datepart("ww",{table.date})

This assumes that the week containing January 1 is week 1, and that the week starts on Sunday.

-LB
 
First you need to determine how the week was determined as there are different means.

My memory is a little fuzzy on this but I seem to recall that the ISO standard states that week 1 is the week which includes the first Tuesday, which is how Oracle calculates a work week.

In either case, the above formulas work if the work week was stored as a result of it NOT being the ISO standard (as I believe how SQL Server does it, as opposed to Oracle).

If you had bothered to include any technical information I would have researched this once again (I went through this years ago for a project).

Also keep in mind that some firms start counting their work weeks as January 1st being the first day of week 1.

Try posting technical information and provide examples of any dates associated with the weeks as stored if you need additional help.

Good luck with it.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top