473,320 Members | 1,821 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,320 software developers and data experts.

Datepart - unable to set first week to Nov 1 to calc # of weeks

1
I want to use the Datepart function to determine the week number based on my company's fiscal calendar which starts Nov. 1.

I have tried the following and they all produce #ERROR# .

DatePart("ww",[Change Calendar qry 1]![Target Date],2,"11/01/2005")
DatePart("ww",[Change Calendar qry 1]![Target Date],2,#11/1/2005#)

If leave the Nov 1 date out, I get a result that appears to be based on Jan 1 as the date. It also appears to be the week number in the year, such that Jan 1 in 2005 and 2006 both have a week number of 1.

The end result I'm looking for the following results
Nov 1, 2005, results in week number 1
Nov 1, 2006, results in week number 53.
Any help or insight would be appreciated.
Thanks
Nov 1 '06 #1
9 2530
NeoPa
32,556 Expert Mod 16PB
So you will always want the week number to be relative to 1 Nov 2005?
Nov 1 '06 #2
NeoPa
32,556 Expert Mod 16PB
Try :-
Expand|Select|Wrap|Line Numbers
  1. WeekNo = (DateDiff("d", #1 Nov 2005#, [Change Calendar qry 1]![Target Date]) \ 7) + 1
BTW
firstweekofyear Optional.A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs.
Expand|Select|Wrap|Line Numbers
  1. Constant        Value    Description
  2. vbUseSystem    0    Use the NLS API setting.
  3. vbFirstJan1    1    Start with week in which January 1 occurs (default).
  4. vbFirstFourDays    2    Start with the first week that has at least four days in the new year.
  5. vbFirstFullWeek    3    Start with first full week of the year.
Nov 1 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
It won't work because this function only allows you to start the year on Jan 1.

As a work around:-

Expand|Select|Wrap|Line Numbers
  1.  
  2.     If Month(Date) >= 11 Then
  3.         WeekNo = DatePart("ww", [Change Calendar qry 1]![Target Date]) - DatePart("ww", "01/11/" & Year(Date))
  4.     Else
  5.         WeekNo = DatePart("ww", [Change Calendar qry 1]![Target Date]) + (52 - DatePart("ww", "01/11/" & Year(Date))
  6.     End If
  7.  
  8.  
Nov 1 '06 #4
VALIS
21
It won't work because this function only allows you to start the year on Jan 1.

As a work around:-

Expand|Select|Wrap|Line Numbers
  1.  
  2.     If Month(Date) >= 11 Then
  3.         WeekNo = DatePart("ww", [Change Calendar qry 1]![Target Date]) - DatePart("ww", "01/11/" & Year(Date))
  4.     Else
  5.         WeekNo = DatePart("ww", [Change Calendar qry 1]![Target Date]) + (52 - DatePart("ww", "01/11/" & Year(Date))
  6.     End If
  7.  
  8.  
How about using =Ceiling((now()-#01/11/05#)/7,1)
Nov 2 '06 #5
MMcCarthy
14,534 Expert Mod 8TB
How about using =Ceiling((now()-#01/11/05#)/7,1)
Ceiling and Floor are Excel Functions. You can attach the Excel library to use then or simply add the functions to a module in your code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function Ceiling(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
  3.     ' X is the value you want to round
  4.     ' is the multiple to which you want to round
  5.     Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor
  6. End Function
  7.  
  8. Public Function Floor(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
  9.     ' X is the value you want to round
  10.     ' is the multiple to which you want to round
  11.     Floor = Int(X / Factor) * Factor
  12. End Function
  13.  
  14.  
Nov 7 '06 #6
NeoPa
32,556 Expert Mod 16PB
It won't work because this function only allows you to start the year on Jan 1.
You should try it - You may just be surprised.

WeekNo = (DateDiff("d", #1 Nov 2005#, [Change Calendar qry 1]![Target Date]) \ 7) + 1
will give you exactly what you need.
Nov 7 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
You should try it - You may just be surprised.

WeekNo = (DateDiff("d", #1 Nov 2005#, [Change Calendar qry 1]![Target Date]) \ 7) + 1
will give you exactly what you need.
I meant the DatePart function Adrian not DateDiff...

Mary
Nov 7 '06 #8
NeoPa
32,556 Expert Mod 16PB
I meant the DatePart function Adrian not DateDiff...

Mary
It's a day for misunderstandings ;)
My bad.
-Adrian.
Nov 8 '06 #9
MMcCarthy
14,534 Expert Mod 8TB
It's a day for misunderstandings ;)
My bad.
-Adrian.
That was an easy one to make.

Don't feel bad about the other it's been resolved with all parties happy.

Mary
Nov 8 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David | last post by:
Hi Group, i am trying to use the DatePart function on my SQL2000 database. I have a table called visitors with a field called DateTimeEntrance which is filled everytime a visitor enters the site....
3
by: Chumley the Walrus | last post by:
I'm trying to use DatePart and Datediff functions to show the formatted m/dd/yyyy display for the dates of Monday and Friday of the current week. I want it to display as: Our Weekly Schedule...
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: Alicia | last post by:
Hi, I am trying to group by week and do a count of my data in between the dates. In Microsoft Access. Something similar to Before: Date Count --------- ---------...
3
by: haydn_llewellyn | last post by:
Hi, My company runs on a fiscal calendar that starts on the first monday in July, and is based on a 13 week quarter (4 weeks, 4 weeks, 5 weeks). What I need, is a way of relating Date() to the...
2
by: Aaran76 | last post by:
I am creating a booking system in ASP.Net with VB and a MSSQL backend. I am having problems knowing where to begin with a particular part of the system. Bookings can only be made in weekly...
3
by: S. van Beek | last post by:
Dear reader, With DatePart() you can subtract the year or the week from a date field with: DatePart("yyyy";) for the year
7
by: tasmontique | last post by:
I have an access table that outputs to excel using a query . However what I am trying to do is under the arrival date column specify a criteria based on the Datepart function that only displays...
1
by: Spoogledrummer | last post by:
Hi, I've run across a problem with on one of the applications I work on. A report uses the group by datepart (wk,Date) but as this is 2007 it messes up as it sees there being 53 weeks so breaks a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.