Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DatePart Function Problem??

Status
Not open for further replies.

cab80

Programmer
Aug 21, 2007
1
AU
Hi All,

Need help...

I am trying to use the datepart or format function to return the week of year. I need Sunday to be the first day and the week containing Jan 1 to be the first week of the year.

I am going nuts because no matte what I do, I cannot get any date like 31 Dec 2008 to be week 1 using the following -

wk = datepart("ww", #31/12/2008#, vbsunday, vbfirstjan1)

this always returns week 53!!

Am I missing something or is this wrong?

 
There doesn't seem to be an easy solution. You could try an expression like:
Code:
wk = datepart("ww", DateAdd("d",7-Weekday(#12/31/2008#),#12/31/2008#), vbsunday, vbfirstjan1)

Duane
Hook'D on Access
MS Access MVP
 
What is wrong with week 53. If January 1,2009 is on a Thursday then would you not have 53 weeks (51 entire weeks and 2 partial weeks)?

If it is a really big deal then make if wk=53 then wk=52

of course this will make everything from dec 21,2008 to the end of the year say week 52.

If you want actual weeks and not calendar weeks then this would be another issue. For example Jan 1 to 7 week 1 8 - 14 week 2 and so on.

ck1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top