Enjoy an ad free experience by logging in. Not a member yet?
Register .
10-04-2002, 08:19 PM
PM User |
#1
Regular Coder
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 593
Thanks: 1
Thanked 19 Times in 19 Posts
Get Week Number
The following will give you the week number for the current date or for a specified date. It can do weeks beginning on Sunday with January 1st always in week 1, starting on Monday with January 1st always in week 1, starting on Monday with January 4th always in week 1 (ISO-8601), or starting on Sunday or Monday starting with the first FULL week:
function GetWeek(GW_Type,GW_Date) {
// GW_Types:
// SS1 Sunday-Saturday, Jan 1 always in week 1.
// MS1 Monday-Sunday, Jan 1 always in week 1.
// MS4 Monday-Sunday, Jan 4 always in week 1 (ISO-8601).
// SS7 Sunday-Saturday, first FULL week is week 1.
// MS7 Monday-Sunday, first FULL week is week 1.
// GW_Date:
// Optional current date formatted as MM/DD/YYYY. Jan-Dec=1-12.
GW_Type=GW_Type.toUpperCase();
if (typeof(GW_Date) == 'undefined') {
GW_Now=new Date();   ; // today
} else {
GW_ix1=GW_Date.indexOf('/'); // find first slash
GW_M=GW_Date.substring(0,GW_ix1); &nbs p;// ...get the month
GW_Work=GW_Date.substring(GW_ix1+1); // ...rest of item
GW_ix1=GW_Work.indexOf('/'); // second slash
GW_D=GW_Work.substring(0,GW_ix1); &nbs p;// ...date
GW_Y=GW_Work.substring(GW_ix1+1); &nbs p;// ...year
GW_Now=new Date(GW_Y, GW_M-1, GW_D); // target date
}
GW_Now_Y=GW_Now.getYear(); &n bsp; // current year
if (GW_Now_Y < 70) { GW_Now_Y=GW_Now_Y*1+2000;  ;}
if (GW_Now_Y < 1900) { GW_Now_Y=GW_Now_Y*1+1900; }
GW_Then=new Date(GW_Now_Y, 0, 1); &nbs p; // Jan 1 of current year
GW_Then_Day=GW_Then.getDay();   ; // Jan 1 day of the week
GW_Diff=GW_Now*1-GW_Then*1; // difference in miliseconds
GW_Days=GW_Diff/(1000*60*60*24); // ...in days
GW_Days=Math.floor(GW_Days+(1/24)); // Daylight Savings Time correction
GW_Week='*** Error';
if (GW_Type == 'SS1') { &nb sp; // Sun-Sat, Jan 1 in week 1
GW_Week=Math.floor((GW_Days+GW_Then_Day)/7)+1;
}
if (GW_Type == 'MS1') { &nb sp; // Mon-Sun, Jan 1 in week 1
GW_Week=Math.floor((GW_Days+GW_Then_Day+6)/7);
}
if (GW_Type == 'MS4') { &nb sp; // Mon-Sun, Jan 4 in week 1 (ISO-8601)
GW_Work=(GW_Then_Day+2)%7;
GW_Week=Math.floor((GW_Days+GW_Work+4)/7);
}
if (GW_Type == 'SS7') { &nb sp; // Sun-Sat, first FULL week is #1
GW_Work=(GW_Then_Day+6)%7;
GW_Week=Math.floor((GW_Days+GW_Work+1)/7);
}
if (GW_Type == 'MS7') { &nb sp; // Mon-Sun, first FULL week is #1
GW_Work=(GW_Then_Day+5)%7;
GW_Week=Math.floor((GW_Days+GW_Work+1)/7);
}
return GW_Week;
}
Last edited by jalarie; 10-07-2002 at 02:11 PM ..
10-07-2002, 11:47 PM
PM User |
#2
New to the CF scene
Join Date: Oct 2002
Location: USA
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
OK. I want to use this, or some of this, but it looks a little overwhelming. I just want to display the correct html file for the correct week (Monday to Sunday).
__________________
-JC
10-08-2002, 01:21 PM
PM User |
#3
Regular Coder
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 593
Thanks: 1
Thanked 19 Times in 19 Posts
J__C, Save the function as-is. I'll make the assumption that you want January 1st to be in the first week even if it is not a full week. Call the function like this:
Week=GetWeek('ms1');
Use "Week" as part of the name of the html file that you wish to display.
If you need more help, please feel free to contact me directly at:
jalarie@umich.edu
10-25-2002, 02:09 PM
PM User |
#4
Regular Coder
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 593
Thanks: 1
Thanked 19 Times in 19 Posts
For whatever it's worth: I recently acquired a Palm PC and found that the week number that it reports is the ISO-8601 standard.
11-03-2002, 06:30 AM
PM User |
#5
New Coder
Join Date: Sep 2002
Location: New York
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
thanks
this one works great.
when my site is finished , i'll show you how i use it.
thanks so much.
12-03-2002, 02:30 PM
PM User |
#6
Regular Coder
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 593
Thanks: 1
Thanked 19 Times in 19 Posts
bcbasslet, is your site up yet? I'm eager to see what you've done.
12-06-2002, 02:27 AM
PM User |
#7
New Coder
Join Date: Sep 2002
Location: New York
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
yes its working
but i had to fire my client , 2.p.i.t.a.
i'll repost all the site to my beta server
as soon as i get my zipdrive at the office
it will be
www.stroudsburgfoto.com/susan
I'll try to get it done by the end of the weekend
the code is so swell!!! what fun it was to do, with your help
too bad the client wasn't.
__________________
WebFocus developer
12-06-2002, 05:50 AM
PM User |
#8
New Coder
Join Date: Sep 2002
Location: New York
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
ok, the code is back on the beta site
the script getweek.js is here
both the js and the code for the frames where i use it
is in the attached file.
and the site in operation (for a short while) is
www.stroudsburgfoto.com/susan
the main frame of that page figures out what week it is and loads in the appropriate filename for the current week.
THANKS ALL OF YOU FOR ALL YOUR HELP.
__________________
WebFocus developer
01-21-2003, 02:33 PM
PM User |
#9
Regular Coder
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 593
Thanks: 1
Thanked 19 Times in 19 Posts
bcbasslet, glad to have helped.
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 08:50 PM .
Advertisement
Log in to turn off these ads.