473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Week number to date??

Mal
Hello,

Any advice on a function to convert a given week number to a date?
Ideally I'd like the first day of that week.

I'm using this to compare year to year....using the week number as the
common factor.

Mal.
Jan 8 '06 #1
3 17291
On Sun, 08 Jan 2006 03:59:55 GMT, "Mal" <me@myhome.net> wrote:
Hello,

Any advice on a function to convert a given week number to a date?
Ideally I'd like the first day of that week.

I'm using this to compare year to year....using the week number as the
common factor.

Mal.


*not thoroughly tested

Function fGetWeekDate(intWeekNo As Integer, _
Optional intYear As Integer, _
Optional intStartDay As Integer = vbSunday) As Date

Dim dtCheckDate As Date

If intYear = 0 Then intYear = Year(Date)

'get first (intStartDay) of year
dtCheckDate = CDate("1/1/" & intYear)
Do Until WeekDay(dtCheckDate, intStartDay) = intStartDay
dtCheckDate = dtCheckDate + 1
Loop

'adjust if first (intStartDay) of year is week 52 or 53
If DatePart("ww", dtCheckDate, , vbFirstFourDays) >= 52 Then
dtCheckDate = DateAdd("ww", 1, dtCheckDate)
End If

fGetWeekDate = DateAdd("ww", intWeekNo - 1, dtCheckDate)

End Function
Wayne Gillespie
Gosford NSW Australia
Jan 8 '06 #2
This is not as easy as it first appears. It depends on how your week number
is defined, or rather how the week numbering start is defined.

Possible definitions I can think of are:-
Week 1 is the week in which the 1st of January falls
Week 1 is the first full week of the year
Week 1 is the first week of the year which contains four days of the
year.

This is then compounded by how do you define the first day of the week.

IIRC the ISO standard is that Monday is the first day of the week and the
first week of the year is the first week which contains four days of the
year.

In short until you define how your week number and first day of the week are
defined it's not possible to answer the question.
--
Terry Kreft

"Mal" <me@myhome.net> wrote in message
news:%6*****************@newsread3.news.atl.earthl ink.net...
Hello,

Any advice on a function to convert a given week number to a date?
Ideally I'd like the first day of that week.

I'm using this to compare year to year....using the week number as the
common factor.

Mal.

Jan 8 '06 #3
Mal wrote:
Hello,

Any advice on a function to convert a given week number to a date?
Ideally I'd like the first day of that week.

I'm using this to compare year to year....using the week number as the
common factor.

Mal.

Expanding a bit on what others wrote, you can view these results in the
Immediate/Debug window
? format(#1/1/2006#,"ww",vbMonday,vbFirstFourDays)
52
? format(#1/1/2006#,"ww",vbMonday,vbFirstFullWeek)
52
? format(#1/1/2006#,"ww",vbMonday,vbFirstJan1)
1
? format(#1/1/2006#,"ww",vbMonday,vbUseSystem)
1
? weekday(#1/1/2006#,vbSunday)
1
? weekday(#1/1/2006#,vbMonday)
7

1/1/2006 is a Sunday. vbSunday is the default in the Weekday function.
Which day is your default? Sunday, Monday...Saturday?

I guess you'll need to find out what the week number is for the first of
the year. Then if the week day is not the start week day either
increment or decrement the days till you get your start day from the
first of the year. From there you can multiply the number of (weeks-1)
* 7. If the week is 52, you'd want to set the week to 0.

Jan 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
4
by: Mark | last post by:
Hi I have been trying to convert the week number to a range of dates that I can use. It should be fairly simple for you guru's out there but for us mere mortals it is beyond our grasp. I know...
14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
5
by: Peter Bailey | last post by:
I have a query that returns , and : 12/05/04 3 Wednesday 13/05/04 0 Thursday and so on what I would like to do now is count the number of bookings by week so from monday to...
9
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a...
2
by: Rustan | last post by:
Hi Im using GregorianCalendar to find out the current years week numbers. When the user chooses a week number in a dropdown i want to show that week in a table with the corresponding dates. For...
6
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
3
by: sbaird | last post by:
Aloha from Hawaii, I'm beating my head on the wall here. I have a recruiting contact managment database I'm trying to create. Managers (there ar 14 of them) have to make a certain number of...
4
by: Vince | last post by:
Given a week Number, how do I calculate the date that for the Monday of that week?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.