figure out a date

Results 1 to 3 of 3

Thread: figure out a date

  1. #1
    Join Date
    Dec 1969

    Default figure out a date

    Hello,<BR><BR>I need to figure out the date when this has been given<BR><BR>the year, the weeknumber and the daynumber(sunday=0 etc)<BR><BR>is there a command to retrieve the date of this<BR>or should I try something like this<BR><BR>guess=array(1,1,1,1,1,2,2,2,2...)<BR>m onth=guess(week)<BR>and then a loop to add/sub a day till the specified day/week/year is reached ?<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: figure out a date

    *<BR>dtDate = DateSerial(year,1,1) &#039;gives 1st January that year<BR>dtDate = DateAdd("ww",weeknnumber-1,dtDate) &#039;adds weeks<BR><BR>do until DatePart("w",dtDate)=0 &#039;"w" gives day of week<BR> dtDate = DateAdd("d",1,dtDate)<BR>loop<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Big mistake in that!

    do until DatePart("w",dtDate)=0<BR><BR>That condition will NEVER be true, so the loop will NEVER END!<BR><BR>READ:<BR><BR><BR>(The WeekDay function returns the same thing as does DatePart("w"...). I have no idea why people like to use DatePart instead of the simpler named functions such as WeekDay.)<BR><BR>There are several other things wrong with that code.<BR><BR>Suppose you wanted Tuesday in the 7th week of the year.<BR><BR>Suppose 1 Jan 20XX happens to fall on Monday.<BR>You then add 6 weeks (number of weeks minus 1, per Ian&#039;s forumla) to that. <BR>You are *STILL* on Monday, just 6 weeks later.<BR>Now, you add days one at a time until you hit Tuesday.<BR>But you add just ONE day are still in WEEK 6! *NOT* in week 7!<BR><BR>***************<BR><BR>But the big unanswered question in this is: WHAT is your definition of the beginning of the first week of the year????<BR><BR>Does it start on Jan 1? Or does it start on Sunday, on or before Jan 1? Or what?<BR><BR>You should read the choices you have, in VBS, here:<BR><BR><BR>Notice that having the week start exactly on Jan 1 is *NOT* an available option. If you want to use that, you can, but then you&#039;ll need to add days (seven times number of weeks) instead of using DatePart and DateAdd.<BR><BR>Oh...and also look to see what the values for days of the week are. As I said, there is NO day number 0. vbSunday is 1 and vbSaturday is 7.<BR><BR>

Posting Permissions

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