473,407 Members | 2,312 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,407 software developers and data experts.

Dates and week numbers

Using the function datepart I can return a week number given any date.
What I now want to do is return a date (say monday) given a week
number. How can I do this?
Alex
Nov 12 '05 #1
6 3229
Alex wrote:
Using the function datepart I can return a week number given any date.
What I now want to do is return a date (say monday) given a week
number. How can I do this?
Alex


See if
Dim intInterval As Integer
intInterval = 2 '2nd week or the year
DateAdd("ww",intInterval,#1/1/2004#) + (vbMonday -
WeekDay(#1/1/2004#))
works.

You need to change vbMonday to whatever day or week you want for more
flexibility Basically this routine adds the weeks to the first of the
year and then points to the day in the week by subtracting the weekday of
the first of the year to whavever weekday you select.

Nov 12 '05 #2
> Using the function datepart I can return a week number given any date.
What I now want to do is return a date (say monday) given a week
number. How can I do this?


Try this "air code" function which should be copied to a standard module (a
global module, not a module behind a form or report):

'*********CODE START
Public Function GetDateByYearWeekNumWeekDay(iYear As Integer, _
iWeekNum As Integer, iWeekDayNum As Integer) As Date
Dim vdate As Date
vdate = DateSerial(iYear, 1, 1) + ((iWeekNum - 1) * 7)
GetDateByYearWeekNumWeekDay = DateValue(vdate - Weekday(vdate) + iWeekDayNum)
End Function
'*********CODE END

Usage:

MyDate = GetDateByYearWeekNumWeekDay(2004,12,vbThursday)

Which returns:

3/18/2004 (Thursday in the 12th week of this year)

--
Bruce M. Thompson, Microsoft Access MVP
bt******@mvps.org (See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.<<

Nov 12 '05 #3
Excellent. Works a treat. Thank you.
Alex

"Bruce M. Thompson" <bthmpson@big_NOSPAM_foot.com> wrote in message
news:vv************@corp.supernews.com...
Using the function datepart I can return a week number given any date.
What I now want to do is return a date (say monday) given a week
number. How can I do this?
Try this "air code" function which should be copied to a standard module

(a global module, not a module behind a form or report):

'*********CODE START
Public Function GetDateByYearWeekNumWeekDay(iYear As Integer, _
iWeekNum As Integer, iWeekDayNum As Integer) As Date
Dim vdate As Date
vdate = DateSerial(iYear, 1, 1) + ((iWeekNum - 1) * 7)
GetDateByYearWeekNumWeekDay = DateValue(vdate - Weekday(vdate) + iWeekDayNum) End Function
'*********CODE END

Usage:

MyDate = GetDateByYearWeekNumWeekDay(2004,12,vbThursday)

Which returns:

3/18/2004 (Thursday in the 12th week of this year)

--
Bruce M. Thompson, Microsoft Access MVP
bt******@mvps.org (See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.<<

Nov 12 '05 #4
> Excellent. Works a treat. Thank you.

You're quite welcome. Keep in mind the fact that it's "air code" and really
*should* have the benefit of some error-handling, but if you're careful in how
you pass the parameters to the function, you shouldn't have too many problems.

:-)
--
Bruce M. Thompson, Microsoft Access MVP
bt******@mvps.org (See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.<<
Nov 12 '05 #5
al********@hotmail.com (Alex) wrote in message news:<49**************************@posting.google. com>...
Using the function datepart I can return a week number given any date.
What I now want to do is return a date (say monday) given a week
number. How can I do this?
Alex


You could do something like
'air code... (insert air code siren sound...)

Function GetNextDate(dtInitialDate as date, intWeeks at integer,intDayNo as integer)

'intDayNo will correspond to vbMonday-vbSunday...
dim dtDate as date

dtDate = Dateadd("w",intWeeks,dtInitialDate)

do until weekday(dtDate)=intDayNo
dtDate=Dateadd("d",1,dtDate)
loop

GetNextDate =dtDate

End Function

Hope this gets you started.

Pieter
Nov 12 '05 #6
On 5 Jan 2004 11:18:45 -0800, al********@hotmail.com (Alex) wrote:
Using the function datepart I can return a week number given any date.
What I now want to do is return a date (say monday) given a week
number. How can I do this?


Did you consider something like this?

SELECT CalDate
FROM Calendar
WHERE (
(CalYear = 2003) AND
(CalDOW = 'Mon') AND
(ISOWeekNum = 8)
)

Implementation of the table Calendar is left as an exercise. ;)

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

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

Similar topics

3
by: Dave Griffiths | last post by:
Hi I am trying to get JS to work out week numbers for given dates, I'm sure this is possible. Any help would be welcomed at this point. Thanks in advance.
8
by: netsurfer | last post by:
Hi: Have a question on making the date automatically filled in by what the user enters in by the date at the top. The date entered at the top would most likely be on a Wednesday then I need...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
2
by: toedipper | last post by:
Hello, MYsql and PHP If I want to extract data with todays date then it's 'where blab blah = current_date()' For yesterday it's 'where blah blah = current_date()-1' But can anyone tell...
5
by: Bullschmidt | last post by:
If I know the week number and the year, how can I calc the beginning and ending dates of the week? For background I'm going to do some grouping by week but don't just want to call the weeks Week...
2
by: Simon Pleasants | last post by:
I recently built a database to help keep track of shipments we are bringing into the country. Included in the database are a number of fields with dates for shipment, ETA etc. Each one of these...
1
by: Alicia | last post by:
I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date Total number of times that date Appeared (Count) 4/3/03 ...
6
by: Bill R via AccessMonster.com | last post by:
I have a query: SELECT tblCalendar.CalendarDay AS LastSunday FROM tblCalendar WHERE (((tblCalendar.CalendarDay)>=(Now()-7) And (tblCalendar.CalendarDay)...
5
by: Elainie | last post by:
I need to get the dates between now and next week but using Now and Next week not any specific dates... Please help, going mad... Elaine
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
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
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.