Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Get Week Number

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    632
    Thanks
    1
    Thanked 21 Times in 21 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();        &nbsp ;             // 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
    &nbsp;&nbsp;if&nbsp;(GW_Now_Y&nbsp;<&nbsp;70)&nbsp;&nbsp;&nbsp;{&nbsp;GW_Now_Y=GW_Now_Y*1+2000;&nbsp ;}
    &nbsp;&nbsp;if&nbsp;(GW_Now_Y&nbsp;<&nbsp;1900)&nbsp;{&nbsp;GW_Now_Y=GW_Now_Y*1+1900;&nbsp;}
    &nbsp;&nbsp;GW_Then=new&nbsp;Date(GW_Now_Y,&nbsp;0,&nbsp;1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;//&nbsp;Jan&nbsp;1&nbsp;of&nbsp;current&nbsp;year
    &nbsp;&nbsp;GW_Then_Day=GW_Then.getDay();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;//&nbsp;Jan&nbsp;1&nbsp;day&nbsp;of&nbsp;the&nbsp;week
    &nbsp;&nbsp;GW_Diff=GW_Now*1-GW_Then*1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;difference&nbsp;in&nbsp;miliseconds
    &nbsp;&nbsp;GW_Days=GW_Diff/(1000*60*60*24);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;...in&nbsp;days
    &nbsp;&nbsp;GW_Days=Math.floor(GW_Days+(1/24));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Daylight&nbsp;Savings&nbsp;Time&nbsp;correction
    &nbsp;&nbsp;GW_Week='***&nbsp;Error';
    &nbsp;&nbsp;if&nbsp;(GW_Type&nbsp;==&nbsp;'SS1')&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Sun-Sat,&nbsp;Jan&nbsp;1&nbsp;in&nbsp;week&nbsp;1
    &nbsp;&nbsp;&nbsp;&nbsp;GW_Week=Math.floor((GW_Days+GW_Then_Day)/7)+1;
    &nbsp;&nbsp;}
    &nbsp;&nbsp;if&nbsp;(GW_Type&nbsp;==&nbsp;'MS1')&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Mon-Sun,&nbsp;Jan&nbsp;1&nbsp;in&nbsp;week&nbsp;1
    &nbsp;&nbsp;&nbsp;&nbsp;GW_Week=Math.floor((GW_Days+GW_Then_Day+6)/7);
    &nbsp;&nbsp;}
    &nbsp;&nbsp;if&nbsp;(GW_Type&nbsp;==&nbsp;'MS4')&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Mon-Sun,&nbsp;Jan&nbsp;4&nbsp;in&nbsp;week&nbsp;1&nbsp;(ISO-8601)
    &nbsp;&nbsp;&nbsp;&nbsp;GW_Work=(GW_Then_Day+2)%7;
    &nbsp;&nbsp;&nbsp;&nbsp;GW_Week=Math.floor((GW_Days+GW_Work+4)/7);
    &nbsp;&nbsp;}
    &nbsp;&nbsp;if&nbsp;(GW_Type&nbsp;==&nbsp;'SS7')&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Sun-Sat,&nbsp;first&nbsp;FULL&nbsp;week&nbsp;is&nbsp;#1
    &nbsp;&nbsp;&nbsp;&nbsp;GW_Work=(GW_Then_Day+6)%7;
    &nbsp;&nbsp;&nbsp;&nbsp;GW_Week=Math.floor((GW_Days+GW_Work+1)/7);
    &nbsp;&nbsp;}
    &nbsp;&nbsp;if&nbsp;(GW_Type&nbsp;==&nbsp;'MS7')&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Mon-Sun,&nbsp;first&nbsp;FULL&nbsp;week&nbsp;is&nbsp;#1
    &nbsp;&nbsp;&nbsp;&nbsp;GW_Work=(GW_Then_Day+5)%7;
    &nbsp;&nbsp;&nbsp;&nbsp;GW_Week=Math.floor((GW_Days+GW_Work+1)/7);
    &nbsp;&nbsp;}
    &nbsp;&nbsp;return&nbsp;GW_Week;
    }
    Last edited by jalarie; 10-07-2002 at 03:11 PM.

  • #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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    632
    Thanks
    1
    Thanked 21 Times in 21 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:

    &nbsp;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:

    &nbsp;jalarie@umich.edu

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    632
    Thanks
    1
    Thanked 21 Times in 21 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.

  • #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.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    632
    Thanks
    1
    Thanked 21 Times in 21 Posts
    bcbasslet, is your site up yet? I'm eager to see what you've done.

  • #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

  • #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.

    Attached Files Attached Files
    WebFocus developer

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    632
    Thanks
    1
    Thanked 21 Times in 21 Posts
    bcbasslet, glad to have helped.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •