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
Solved

Calculate week number offset against a date.

Posted on 2006-11-08
7
784 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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