converting a week# to a date


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: converting a week# to a date

  1. #1
    rich Guest

    converting a week# to a date


    does anyone know of a way to convert a week# to a date? for example: week
    32 is equivalent to august 8. thanks in advance.

  2. #2
    Patrick Marshall Guest

    Re: converting a week# to a date


    Hi Kathleen & Rich,

    There are some implicit assumptions in week # to date conversions:

    1. Start day of week (start Sunday, Monday, etc.)
    2. Need year as an input since you don't have the same date for
    the same week # each year

    Example for Sunday as start day of week:

    Public Function SundayDateFromWkNumber(YrInt As Integer, WeekNumInt As Integer)
    As Date
    'returns date from week number and year
    Dim StartDate As Date
    Dim DayOfWeekInt As Integer
    Dim TempDate As Date
    'assume Sunday is day one of week
    DayOfWeekInt = WeekDay("1/1/" & CStr(YrInt))
    'if sunday is NOT the start of your week, you must add logic to case
    statement below
    Select Case DayOfWeekInt
    Case 1
    StartDate = CDate("1/1/" & CStr(YrInt))
    Case 2 To 7
    StartDate = CDate("1/" & CStr(9 - DayOfWeekInt) & "/" & CStr(YrInt))
    Case Else
    End Select
    TempDate = DateAdd("ww", WeekNumInt - 1, StartDate)
    If WeekDay(TempDate) = 1 Then
    SundayDateFromWkNumber = TempDate
    Else
    SundayDateFromWkNumber = DateAdd("d", 2 - DayOfWeekInt, TempDate)
    End If

    End Function

    <Patrick>

    "Kathleen Dollard-Joeris" <kjoeris@noemailplease.com> wrote:
    >Rich,
    >
    >I think the DateDiff function starting at the Jan. 1 in the year you are
    >interested in is probably the easiest way to accomplish this.
    >
    >--
    >Kathleen
    >(MS-MVP)
    >Reply in the newsgroup so everyone can benefit
    >--
    >
    >"rich" <rperez@teleteam.net> wrote in message
    >news:39a56483$1@news.devx.com...
    >>
    >> does anyone know of a way to convert a week# to a date? for example:

    week
    >> 32 is equivalent to august 8. thanks in advance.

    >
    >



  3. #3
    Kathleen Dollard-Joeris Guest

    Re: converting a week# to a date

    Rich,

    I think the DateDiff function starting at the Jan. 1 in the year you are
    interested in is probably the easiest way to accomplish this.

    --
    Kathleen
    (MS-MVP)
    Reply in the newsgroup so everyone can benefit
    --

    "rich" <rperez@teleteam.net> wrote in message
    news:39a56483$1@news.devx.com...
    >
    > does anyone know of a way to convert a week# to a date? for example: week
    > 32 is equivalent to august 8. thanks in advance.




  4. #4
    Rick Rothstein Guest

    Re: converting a week# to a date

    I think perhaps you mean DateAdd; something on the order of

    YearValue = 2000
    WeekNumber = 32
    NewDate = DateAdd("ww", WeekNumber, "1/1/" & CStr(YearValue))

    Rick


    "Kathleen Dollard-Joeris" <kjoeris@noemailplease.com> wrote in message
    news:39a57782$1@news.devx.com...
    > Rich,
    >
    > I think the DateDiff function starting at the Jan. 1 in the year you are
    > interested in is probably the easiest way to accomplish this.
    >
    > --
    > Kathleen
    > (MS-MVP)
    > Reply in the newsgroup so everyone can benefit
    > --
    >
    > "rich" <rperez@teleteam.net> wrote in message
    > news:39a56483$1@news.devx.com...
    > >
    > > does anyone know of a way to convert a week# to a date? for example:

    week
    > > 32 is equivalent to august 8. thanks in advance.

    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center