Solved

Calculate week number offset against a date.

Posted on 2006-11-08
7
787 Views
Last Modified: 2013-12-18
Hi,

I currently use the following formula to calculate the current week number:

Datum:= @If(@IsTime(Date); Date; @Now);
y:=@Year(Datum);
jan1:=@Date(y;1;1);
day1:= @Adjust(jan1; 0; 0; 3-@Modulo(@Weekday(jan1)+1; 7); 0; 0; 0);
jan1l:=@Date(y-1;1;1);
day1l:=@Adjust(jan1l; 0; 0; 3-@Modulo(@Weekday(jan1l)+1; 7); 0; 0; 0);
jan1n:=@Date(y+1;1;1);
day1n:=@Adjust(jan1n; 0; 0; 3-@Modulo(@Weekday(jan1n)+1; 7); 0; 0; 0);
offset:=@If(Datum<day1; day1l; Datum<day1n; day1; day1n);
@Integer((Datum-offset)/86400/7)+1

What I would like to do is calculate the week number from the first Saturday after the 6th April of each year.

So for example if the first Saturday in April is the 7th then this would be week 1
if the first Saturday is the 5th then this would be week 53

Is there any way the above formula can be modified to achieve this?
0
Comment
Question by:shuboarder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 17899886
Sure, but I am not a formula expert.

I would think that all you need to do is change the beginning date to work from April 6 instead of Jan 1.

I hope this helps !
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 17899898
So first would be to calculate the first Sat after April 6, and then plug it in whenever Jan1 is used.

SOmeone here can figure it out.

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17902881
You might try to set jan1 (which is used as reference date) to your preferred reference date, but there are some weird snags in the standard weeknumber computation. No, won't work. If someone hasn't solved this puzzle by tomorrow, I'll certainly give it a try...

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 250 total points
ID: 17905019
Some info missing: a week starts on what day: Sat/Sun/Mon?

Try with this code, it assumes Monday as the first day of the week:

Datum:= @If(@IsTime(Date); Date; @Now);
y:=@Year(Datum);
jan1:=@Date(y;4;6);
day1:= @Adjust(jan1; 0; 0; 5-@Modulo(@Weekday(jan1)+1; 7); 0; 0; 0);
jan1l:=@Date(y-1;4;6);
day1l:=@Adjust(jan1l; 0; 0; 5-@Modulo(@Weekday(jan1l)+1; 7); 0; 0; 0);
jan1n:=@Date(y+1;4;6);
day1n:=@Adjust(jan1n; 0; 0; 5-@Modulo(@Weekday(jan1n)+1; 7); 0; 0; 0);
offset:=@If(Datum<day1; day1l; Datum<day1n; day1; day1n);
@Integer((Datum-offset)/86400/7)+1

Not tested, just applied logic...
0
 
LVL 18

Expert Comment

by:marilyng
ID: 17935230
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17936893
Striking resemblance... but I've never seen it before, honestly.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 17943234
Great minds think alike! :)  I didn't notice the resemblance, to tell the truth.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question