473,750 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Week Number To Date Range

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
Nov 12 '05 #1
4 22689
ka*******@hotma il.com (Mark) wrote:
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


Hi Mark,

This is a function I use to create a table which gives week number agains a
date range. You might be able to adapt this for your purposes. Note that
the date range in the code dictates the start day for each week (currently
a Monday).

HTH - Keith.
www.keithwilby.org.uk

Public Sub libMakeDate()

Dim db As Database
Dim td As TableDef
Dim fd As Field
Dim rs As Recordset
Dim dtmdate As Date

Set db = CurrentDb

' Create a new table
Set td = db.CreateTableD ef("tblDate")

' Create a new field
Set fd = New Field
fd.name = "Date"
fd.Type = dbDate

' Add the field to the table
td.Fields.Appen d fd

' Create a new field
Set fd = New Field
fd.name = "WeekNo"
fd.Type = dbText

' Add the field to the table
td.Fields.Appen d fd

' Add the table to the database
db.TableDefs.Ap pend td

' Open the table
Set rs = td.OpenRecordse t

' Add dates and weekno
For dtmdate = #10/27/02# To #12/31/10# Step 7
rs.AddNew
rs!Date = dtmdate
rs!WeekNo = Year(dtmdate) Mod 10 & Right("0" & Format(dtmdate,
"ww"), 2)
rs.Update
Next
rs.Close

End Sub
Nov 12 '05 #2

Function WeekNoToDate(St artDate As Date, WeekNo As Double) As String

Dim FirstDate As Date, SecondDate As Date

If WeekNo > 52 Or WeekNo < -52 Then
MsgBox "Maximum week no is + or - 52", vbCritical
Exit Function
End If

If Int(WeekNo) <> WeekNo Then
MsgBox "Week No must be a whole number", vbCritical
Exit Function
End If

FirstDate = DateAdd("ww", WeekNo, StartDate)
SecondDate = DateAdd("d", FirstDate, 6)
WeekNoToDate = "From:" & Format(FirstDat e, "Medium Date") & " to:" &
Format(SecondDa te, "Medium Date")

End Function

Watch how the StartDate is entered

WeekNoToDate(#1 apr 03#, 50) is OK
WeekNoToDate(#1/4/03#, 50) gives From:20-Dec-03 to:26-Dec-03 because it
assumes the date is 4th January.
Dates are all daft. Wouldn't it be much more logical to go yyyy/mm/dd. The
Brits have got it completely arse about face, and the Americans are even
more illogical with mm/dd/yyyy.

Phil
"Keith Wilby" <ke*********@Aw ayWithYerCrap.c om> wrote in message
news:Xn******** *************** *@10.15.188.42. ..
ka*******@hotma il.com (Mark) wrote:
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

Hi Mark,

This is a function I use to create a table which gives week number agains

a date range. You might be able to adapt this for your purposes. Note that
the date range in the code dictates the start day for each week (currently
a Monday).

HTH - Keith.
www.keithwilby.org.uk

Public Sub libMakeDate()

Dim db As Database
Dim td As TableDef
Dim fd As Field
Dim rs As Recordset
Dim dtmdate As Date

Set db = CurrentDb

' Create a new table
Set td = db.CreateTableD ef("tblDate")

' Create a new field
Set fd = New Field
fd.name = "Date"
fd.Type = dbDate

' Add the field to the table
td.Fields.Appen d fd

' Create a new field
Set fd = New Field
fd.name = "WeekNo"
fd.Type = dbText

' Add the field to the table
td.Fields.Appen d fd

' Add the table to the database
db.TableDefs.Ap pend td

' Open the table
Set rs = td.OpenRecordse t

' Add dates and weekno
For dtmdate = #10/27/02# To #12/31/10# Step 7
rs.AddNew
rs!Date = dtmdate
rs!WeekNo = Year(dtmdate) Mod 10 & Right("0" & Format(dtmdate,
"ww"), 2)
rs.Update
Next
rs.Close

End Sub

Nov 12 '05 #3
Thank you very much both of you. I will have a look at them now and
tell you how I got on
Mark
"Phil Stanton" <ph**@stantonfa mily.co.uk> wrote in message news:<3f******* *************** *@mercury.nildr am.net>...
Function WeekNoToDate(St artDate As Date, WeekNo As Double) As String

Dim FirstDate As Date, SecondDate As Date

If WeekNo > 52 Or WeekNo < -52 Then
MsgBox "Maximum week no is + or - 52", vbCritical
Exit Function
End If

If Int(WeekNo) <> WeekNo Then
MsgBox "Week No must be a whole number", vbCritical
Exit Function
End If

FirstDate = DateAdd("ww", WeekNo, StartDate)
SecondDate = DateAdd("d", FirstDate, 6)
WeekNoToDate = "From:" & Format(FirstDat e, "Medium Date") & " to:" &
Format(SecondDa te, "Medium Date")

End Function

Watch how the StartDate is entered

WeekNoToDate(#1 apr 03#, 50) is OK
WeekNoToDate(#1/4/03#, 50) gives From:20-Dec-03 to:26-Dec-03 because it
assumes the date is 4th January.
Dates are all daft. Wouldn't it be much more logical to go yyyy/mm/dd. The
Brits have got it completely arse about face, and the Americans are even
more illogical with mm/dd/yyyy.

Phil
"Keith Wilby" <ke*********@Aw ayWithYerCrap.c om> wrote in message
news:Xn******** *************** *@10.15.188.42. ..
ka*******@hotma il.com (Mark) wrote:
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


Hi Mark,

This is a function I use to create a table which gives week number agains

a
date range. You might be able to adapt this for your purposes. Note that
the date range in the code dictates the start day for each week (currently
a Monday).

HTH - Keith.
www.keithwilby.org.uk

Public Sub libMakeDate()

Dim db As Database
Dim td As TableDef
Dim fd As Field
Dim rs As Recordset
Dim dtmdate As Date

Set db = CurrentDb

' Create a new table
Set td = db.CreateTableD ef("tblDate")

' Create a new field
Set fd = New Field
fd.name = "Date"
fd.Type = dbDate

' Add the field to the table
td.Fields.Appen d fd

' Create a new field
Set fd = New Field
fd.name = "WeekNo"
fd.Type = dbText

' Add the field to the table
td.Fields.Appen d fd

' Add the table to the database
db.TableDefs.Ap pend td

' Open the table
Set rs = td.OpenRecordse t

' Add dates and weekno
For dtmdate = #10/27/02# To #12/31/10# Step 7
rs.AddNew
rs!Date = dtmdate
rs!WeekNo = Year(dtmdate) Mod 10 & Right("0" & Format(dtmdate,
"ww"), 2)
rs.Update
Next
rs.Close

End Sub

Nov 12 '05 #4
On 27 Nov 2003 06:54:26 -0800, ka*******@hotma il.com (Mark) wrote:
I have been trying to convert the week number to a range of dates that
I can use.


This is dead simple if you use a table instead of code. (And you
*should* use a table instead of code. Business data belongs in
tables.)

--
Mike Sherrill
Information Management Systems
Nov 12 '05 #5

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

Similar topics

4
5390
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
2
3421
by: David Mitchell | last post by:
I have tried using the following code to count the specific number of each weekday but get a compile error "User defined type not defined" which I think relates to the first line of the function: - Public Function HowManySpecificDays(StartDate As Date, EndDate As Date) As DayCounts and specifically the word "DayCounts" Can anyone help?
14
5108
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,)))
9
7284
by: PamelaDV | last post by:
I have two problems, actually. I am looking to see if there is a function that will return the day of the week (Monday, Tuesday, Wednesday, etc...) from a date. For instance 2/27/04 is a Friday. Also is there a way to group dates by week? I have a user who wants a report to group by week. I know I could create a table and assign dates to a week, but I'm wondering if anyone has anything out there already done that may be a little bit...
3
29038
by: jerry.ranch | last post by:
I have a need to convert simple dates (i.e. 02/14/2005) to a number, do some math, and convert back to a date. (in a simple query). The math involves adding or substracting days, and days of the week . I've used the weekday() function to convert dates to numberic days of the week (1-7) I've used cdbl (date) to convert a date to a serial number, but then I do math with the number and I can't seem to convert this back to a date.
2
2352
by: planetthoughtful | last post by:
Hi All, I'm building some reports in Acc97 and using a custom calendar form to allow users to pick dates with which to report. I'm wondering if there's an easy way in code to be able to automatically work out the end-of-week date and end-of-month date from an arbitrary date value? To explain a little further. Let's say a user wants to view a weekly
3
3524
by: Manekurt | last post by:
Hello, does anyone knows how to convert a date, into a number of week of an year? for example mm/dd/yyyy 01/04/2006 convert to 1 (week number 1 of the year) Thanik you
3
16686
by: Tim Chase | last post by:
I've been trying to come up with a good algorithm for determining the starting and ending dates given the week number (as defined by the strftime("%W") function). My preference would be for a Sunday->Saturday range rather than a Monday->Sunday range. Thus, >>> startDate, stopDate = weekBoundaries(2006, 23) would yield a start-date of June 4, 2006 and an end-date of June
7
9050
by: derekdeben | last post by:
Hi, I have created a report that totals the number of days it took a product to ship by percentage by a date range for a specific location. My data comes from a query with the following headers: I used a count iff to calculate the following headers in the report. This is a percent of the total number of packages.
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
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...
0
9398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9345
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
9257
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
8265
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...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4716
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
4894
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.