473,608 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17327
On Sun, 08 Jan 2006 03:59:55 GMT, "Mal" <me@myhome.ne t> 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(in tWeekNo 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(dtCheck Date, 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.ne t> wrote in message
news:%6******** *********@newsr ead3.news.atl.e arthlink.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",vbMo nday,vbFirstFou rDays)
52
? format(#1/1/2006#,"ww",vbMo nday,vbFirstFul lWeek)
52
? format(#1/1/2006#,"ww",vbMo nday,vbFirstJan 1)
1
? format(#1/1/2006#,"ww",vbMo nday,vbUseSyste m)
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...Saturd ay?

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
5207
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 appreciated. TIA
7
15142
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 attached), yet when I ran it for 28/09/2003 (UK date format) it returned Week 39. I would have expected it to return Week 40. However, I'm really stuck and my head is busting over this, so any pointers would be gratefully appreciated. Many thanks...
4
22662
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 that there are different start days of the week so I would presume any function would provide that facility. Hope you can help Mark
14
5094
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 DateAdd("d", 6, DateAdd("d", -weekday()+2,)))
5
3031
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 friday from the first date get the sum of bookings.
9
3412
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 period and 13 periods a year. normally 52 weeks per year but one 53-week a year every 6 years. The 53th week is included in period 13. Can someone advise any idea how to construct such conversion.
2
34343
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 example : the user choses week43 (this week) so somehow i must calculate what date is startdate that week (monday 18th). How do i do this with c# ? all i know is that its-
6
25356
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 1953 I checked the algorithm it is very correct.
3
2612
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 recruiting calls per week, and so many of them have to result in at least an appointment. However, the "week" is Wednesday, 12:01pm to the following Wednesday, 12:00noon. So here are my questions... 1) Is there a way to change the standard week...
4
10820
by: Vince | last post by:
Given a week Number, how do I calculate the date that for the Monday of that week?
0
8498
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8152
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6817
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6014
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.