-
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.
-
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.
>
>
-
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.
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks