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
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pls help to check why it is only work if the day in on monday

    I do have a code to check on the workweek base on the date given, I have set that first week of the year is ww1 and the last week will be ww52 or ww53.
    below is my code:-
    Code:
    <select name="ww" id="ww">
    <%'use the year of the data of the file and set default as work week of data date
    sDateInfo = split(sData," ")
    dDate1 = cdate(sDateInfo(0)) 'takes the first piece of data from the .DAT file as the default date for work week
    
    tYr = Year(dDate1) 'the year of Data1 date
    strDate = tYr & "/01/01"  'January 1, year whatever
    WDate = cdate(strDate)
    Do Until Weekday(WDate) = 2'Monday
    WDate = WDate + 1
    Loop
    'get the default Monday for actual data
    XDate = dDate1
    Do Until Weekday(XDate) = 2'Monday
    XDate = XDate + 1
    Loop
    'now XDate is default and WDate is the first Monday of the year
    t = 0
    Do Until Year(WDate) <> Year(dDate1)  'only this year's dates
    t = t + 1
    %><option value="<%=t%>" <%if WDate = XDate then%>selected<%end if%>>Week <%=t%> (Begins <%=WDate%>)</option><%
    WDate = WDate + 7 'jump to next monday
    Loop
    %>
    </select>
    I only manage to get the ww correct if the date provided fall on monday.
    for example:-
    my date = mar 06/ mar 13 and also mar 20 it give me the correct ww= ww11,12 and 13.
    when my date is 07,14 and 21 it will give me ww12 ,13 and14

    What I want is any date fall in between 06-12 of march are ww 11. anything after 12 of mar till 19 is under ww 12.

    Hope that everyone understand what I mean and help on this are welcome. tks

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <select name="ww" id="ww">
    <%'use the year of the data of the file and set default as work week of data date
    sDateInfo = split(sData," ")
    dDate1 = cdate(sDateInfo(0)) 'takes the first piece of data from the .DAT file as the default date for work week
    
    tYr = Year(dDate1) 'the year of Data1 date
    strDate = tYr & "/01/01"  'January 1, year whatever
    WDate = cdate(strDate)
    Do Until Weekday(WDate) = 2'Monday
    WDate = WDate + 1
    Loop
    'get the default Monday for actual data
    XDate = dDate1
    '***  If dDate1 falls on a Tuesday Then to find the correct week of the year 
    '***  would mean the previous Monday.  What you are doing is advancing
    '***  one whole week to the next week of the year to set xDate to.
    Do Until Weekday(XDate) = 2'Monday
    XDate = XDate + 1
    Loop
    'now XDate is default and WDate is the first Monday of the year
    t = 0
    Do Until Year(WDate) <> Year(dDate1)  'only this year's dates
    t = t + 1
    %><option value="<%=t%>" <%if WDate = XDate then%>selected<%end if%>>Week <%=t%> (Begins <%=WDate%>)</option><%
    WDate = WDate + 7 'jump to next monday
    Loop
    %>
    </select>
    It sort of seems that you are re-inventing the wheel. VBScript has the ability to calc this for you using DateAdd(). Perhaps you have a reason for not using it that I am unaware of, so I'm not trying to tell you to change it, but only point out there may be a better option available in the event you are unaware of it.

    The red stuff should solve your problem. You will probably have to put in a check for the DOW for the current date so that you can adjust accordingly. In any event any day greater than 2 will need to come back to the Monday before it.

    One other quick thing. By my calculations Mar 6 is the 10 week of the year.

    BaldEagle

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BaldEagle
    Code:
    <select name="ww" id="ww">
    <%'use the year of the data of the file and set default as work week of data date
    sDateInfo = split(sData," ")
    dDate1 = cdate(sDateInfo(0)) 'takes the first piece of data from the .DAT file as the default date for work week
    
    tYr = Year(dDate1) 'the year of Data1 date
    strDate = tYr & "/01/01"  'January 1, year whatever
    WDate = cdate(strDate)
    Do Until Weekday(WDate) = 2'Monday
    WDate = WDate + 1
    Loop
    'get the default Monday for actual data
    XDate = dDate1
    '***  If dDate1 falls on a Tuesday Then to find the correct week of the year 
    '***  would mean the previous Monday.  What you are doing is advancing
    '***  one whole week to the next week of the year to set xDate to.
    Do Until Weekday(XDate) = 2'Monday
    XDate = XDate + 1
    Loop
    'now XDate is default and WDate is the first Monday of the year
    t = 0
    Do Until Year(WDate) <> Year(dDate1)  'only this year's dates
    t = t + 1
    %><option value="<%=t%>" <%if WDate = XDate then%>selected<%end if%>>Week <%=t%> (Begins <%=WDate%>)</option><%
    WDate = WDate + 7 'jump to next monday
    Loop
    %>
    </select>
    It sort of seems that you are re-inventing the wheel. VBScript has the ability to calc this for you using DateAdd(). Perhaps you have a reason for not using it that I am unaware of, so I'm not trying to tell you to change it, but only point out there may be a better option available in the event you are unaware of it.

    The red stuff should solve your problem. You will probably have to put in a check for the DOW for the current date so that you can adjust accordingly. In any event any day greater than 2 will need to come back to the Monday before it.

    One other quick thing. By my calculations Mar 6 is the 10 week of the year.

    BaldEagle
    Hi BaldEagle,
    Tks for the advise, do you mind to show me on the others or easier ways to make this work. From your explanation I think I know what is the problem now, I do try to overcome this but fail to do so, pls help me on solving this problem which had already trouble me for a long time. Tks

  • #4
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is a quick little snippet to address this issue. I have commented it to help you see what each step is for.

    Code:
    <%
      '** this will get the current year
      '** if you leave off the year if will automatically get current one
      '** so this will work no matter what year it is
      thisYear = DatePart("yyyy","01/01")
      
      '** build the date for the first day of the year
      thisDate = "01/01/" & Cstr(thisYear)
      
      '** get the weekday for the first day of the year
      thisWeekDay = DatePart("w",thisDate)
      
      '** this will be either the current system date or it can be obtained
      '** from a user input whichever you prefer ... compare date
      compDate = Date()
      '** calc the week of the year for the current date
      compWeek = DatePart("ww",compDate)
      
      '** this loop will adjust forward or backward to Monday of that week
      For i = 1 to 7
         If DatePart("w",thisDate) > 2 Then
            thisDate = DateAdd("d",-1,thisDate)
         ElseIf DatePart("w",thisDate) < 2 Then
            thisDate = DateAdd("d",1,thisDate)
         ElseIf DatePart("w",thisDate) = 2 Then
            Exit For
         End If 
      Next
      
      '** this will output your select and options 
      '** I made the display show both week of year and Monday date
      '** if that is not neded then adjust the option statements
      '** accordingly, also the value returned from the option is only the weekof the year
      '** so again if this is not exactly how you want you will have to adjust the option statement
      Response.Write("<select>")
      Do While DatePart("yyyy",thisDate) = thisYear
         thisWoy = DatePart("ww",thisDate)
         If thisWoy = compWeek Then
            Response.Write("<option value=""" & thisWoy & """ SELECTED>" & thisWoy & " - " & thisDate & "</option>")
         Else
            Response.Write("<option value=""" & thisWoy & """>" & thisWoy & " - " & thisDate & "</option>")
         End If
         thisDate = DateAdd("d",7,thisDate)
      Loop
      Response.Write("</select>")
    %>
    Hope this is satisfactory for you. If you need more help massaging it into your setup let me know.

    BaldEagle
    Last edited by BaldEagle; 04-10-2006 at 06:47 PM.

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi BaldEagle,
    Thank you very much for your help, a great code & also explanation. It is working now, I will try to play around with it, so that it will be more suitable to my condition, will seek for your help if there is problem. Appreciated your help & support.tks

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BaldEagle
    Here is a quick little snippet to address this issue. I have commented it to help you see what each step is for.

    Code:
    <%
      '** this will get the current year
      '** if you leave off the year if will automatically get current one
      '** so this will work no matter what year it is
      thisYear = DatePart("yyyy","01/01")
      
      '** build the date for the first day of the year
      thisDate = "01/01/" & Cstr(thisYear)
      
      '** get the weekday for the first day of the year
      thisWeekDay = DatePart("w",thisDate)
      
      '** this will be either the current system date or it can be obtained
      '** from a user input whichever you prefer ... compare date
      compDate = Date()
      '** calc the week of the year for the current date
      compWeek = DatePart("ww",compDate)
      
      '** this loop will adjust forward or backward to Monday of that week
      For i = 1 to 7
         If DatePart("w",thisDate) > 2 Then
            thisDate = DateAdd("d",-1,thisDate)
         ElseIf DatePart("w",thisDate) < 2 Then
            thisDate = DateAdd("d",1,thisDate)
         ElseIf DatePart("w",thisDate) = 2 Then
            Exit For
         End If 
      Next
      
      '** this will output your select and options 
      '** I made the display show both week of year and Monday date
      '** if that is not neded then adjust the option statements
      '** accordingly, also the value returned from the option is only the weekof the year
      '** so again if this is not exactly how you want you will have to adjust the option statement
      Response.Write("<select>")
      Do While DatePart("yyyy",thisDate) = thisYear
         thisWoy = DatePart("ww",thisDate)
         If thisWoy = compWeek Then
            Response.Write("<option value=""" & thisWoy & """ SELECTED>" & thisWoy & " - " & thisDate & "</option>")
         Else
            Response.Write("<option value=""" & thisWoy & """>" & thisWoy & " - " & thisDate & "</option>")
         End If
         thisDate = DateAdd("d",7,thisDate)
      Loop
      Response.Write("</select>")
    %>
    Hope this is satisfactory for you. If you need more help massaging it into your setup let me know.

    BaldEagle

    Hi Baldeagle,
    I would like to take the ww for me to save in db database, how can I extract the ww and take away the date behind it and update into database.
    rs ww = ??

    pls help tks

  • #7
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not certain I understand the question. Do you want to save week of the year before processing the form or during form processing?

    BaldEagle

  • #8
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I keep reading your question over and over and I think I understand now. I think the problem may be in this part of the code. I probably should not make assumptions so I'll add to it to hopefully explain better what is going to happen.

    Code:
      '** this will output your select and options 
      '** I made the display show both week of year and Monday date
      '** if that is not neded then adjust the option statements
      '** accordingly, also the value returned from the option is only the weekof the year
      '** so again if this is not exactly how you want you will have to adjust the option statement
    '** you will need to add a name to the select
      Response.Write("<select name=""someName"">")
      Do While DatePart("yyyy",thisDate) = thisYear
         thisWoy = DatePart("ww",thisDate)
    '** there are two paths here to account for the pre-selected item
    '** each will display woy - monday of that week in the drop down
    '** the options statements will pass only the woy to the processing
    '** page 
         If thisWoy = compWeek Then
            Response.Write("<option value=""" & thisWoy & """ SELECTED>" & thisWoy & " - " & thisDate & "</option>")
         Else
            Response.Write("<option value=""" & thisWoy & """>" & thisWoy & " - " & thisDate & "</option>")
         End If
         thisDate = DateAdd("d",7,thisDate)
      Loop
      Response.Write("</select>")
    Now when you process this form (which I didn't include, I am only showing the select) your form processing page should have this:
    mySelect = Request.Form("someName")

    If the item selected is 03/06/2006 then mySelect will contain "10" because in the select options I am passing only the week of the year.

    Does this help? Do you need a better description? Or am I off base as to what you want to accomplish.

    BaldEagle

  • #9
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Baldeagle
    Thank you very much for your help.


  •  

    Posting Permissions

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