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
9 2530 NeoPa 32,556
Expert Mod 16PB
So you will always want the week number to be relative to 1 Nov 2005?
NeoPa 32,556
Expert Mod 16PB
Try :- - 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. - Constant Value Description
- vbUseSystem 0 Use the NLS API setting.
- vbFirstJan1 1 Start with week in which January 1 occurs (default).
- vbFirstFourDays 2 Start with the first week that has at least four days in the new year.
- vbFirstFullWeek 3 Start with first full week of the year.
It won't work because this function only allows you to start the year on Jan 1.
As a work around:- -
-
If Month(Date) >= 11 Then
-
WeekNo = DatePart("ww", [Change Calendar qry 1]![Target Date]) - DatePart("ww", "01/11/" & Year(Date))
-
Else
-
WeekNo = DatePart("ww", [Change Calendar qry 1]![Target Date]) + (52 - DatePart("ww", "01/11/" & Year(Date))
-
End If
-
-
It won't work because this function only allows you to start the year on Jan 1.
As a work around:- -
-
If Month(Date) >= 11 Then
-
WeekNo = DatePart("ww", [Change Calendar qry 1]![Target Date]) - DatePart("ww", "01/11/" & Year(Date))
-
Else
-
WeekNo = DatePart("ww", [Change Calendar qry 1]![Target Date]) + (52 - DatePart("ww", "01/11/" & Year(Date))
-
End If
-
-
How about using =Ceiling((now()-#01/11/05#)/7,1)
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. -
-
Public Function Ceiling(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
-
' X is the value you want to round
-
' is the multiple to which you want to round
-
Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor
-
End Function
-
-
Public Function Floor(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
-
' X is the value you want to round
-
' is the multiple to which you want to round
-
Floor = Int(X / Factor) * Factor
-
End Function
-
-
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.
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
NeoPa 32,556
Expert Mod 16PB
I meant the DatePart function Adrian not DateDiff...
Mary
It's a day for misunderstandings ;)
My bad.
-Adrian.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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....
|
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...
|
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...
|
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
--------- ---------...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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....
|
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
|
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...
| |