Hello All,
I would like to calculate weeknumber and period from first day of the week (sunday) and last day of the week (saturday) and week number falls from 1 to 52 only. If week number >= 53 then week number will equal to 52. And Last Day of First week is the first Saturday of January, as long as it falls at least four days into the month
Example:
if enter
Date WeekNo. Period
12/31/06 1 12/31/06-01/06/07
01/05/07 1 12/31/06-01/06/07
01/09/07 2 01/07/07-01/13/07
12/24/07 52 12/23/07-12/29/07
12/30/07 1 12/30/07-01/05/08
12/29/08 52 12/28/08-01/03/09
01/05/09 1 01/04/09-01/10/09
Any help would be appreciated. Thanks alots.
Codes below is what had for first day of week: 01/01/yyyy
last day of week: 12/31/yyyy.
But it's not the way i want. i would like to calculate week number base on the definition above. Thanks -
dteDate = Me.txtCollDate
-
WeekNumber = Format(dteDate, "ww")
-
Me.txtWeek = WeekNumber
-
-
If WeekNumber = 1 Then
-
FirstDayOfWeek = "1/1/" & Year(dteDate)
-
LastDayOfWeek = dteDate + (7 - Weekday(dteDate))
-
Period = Format(FirstDayOfWeek, "mm/dd/yy") & "-" & Format(LastDayOfWeek, "mm/dd/yy")
-
End If
-
-
If WeekNumber > 1 And WeekNumber < 53 Then
-
FirstDayOfWeek = dteDate - (Weekday(dteDate) - 1)
-
LastDayOfWeek = dteDate - Weekday(dteDate) + 7
-
Period = Format(FirstDayOfWeek, "mm/dd/yy") & "-" & Format(LastDayOfWeek, "mm/dd/yy")
-
End If
-
-
If WeekNumber = 53 Then
-
WeekNumber = 52
-
FirstDayOfWeek = (dteDate - (Weekday(dteDate) - 1)) - 7
-
LastDayOfWeek = "12/31/" & Year(dteDate)
-
Period = Format(FirstDayOfWeek, "mm/dd/yy") & "-" & Format(LastDayOfWeek, "mm/dd/yy")
-
End If
-
4 4682
Hello All,
I would like to calculate weeknumber and period from first day of the week (sunday) and last day of the week (saturday) and week number falls from 1 to 52 only. If week number >= 53 then week number will equal to 52. And Last Day of First week is the first Saturday of January, as long as it falls at least four days into the month
Example:
if enter
Date WeekNo. Period
12/31/06 1 12/31/06-01/06/07
01/05/07 1 12/31/06-01/06/07
01/09/07 2 01/07/07-01/13/07
12/24/07 52 12/23/07-12/29/07
12/30/07 1 12/30/07-01/05/08
12/29/08 52 12/28/08-01/03/09
01/05/09 1 01/04/09-01/10/09
Any help would be appreciated. Thanks alots.
Codes below is what had for first day of week: 01/01/yyyy
last day of week: 12/31/yyyy.
But it's not the way i want. i would like to calculate week number base on the definition above. Thanks -
dteDate = Me.txtCollDate
-
WeekNumber = Format(dteDate, "ww")
-
Me.txtWeek = WeekNumber
-
-
If WeekNumber = 1 Then
-
FirstDayOfWeek = "1/1/" & Year(dteDate)
-
LastDayOfWeek = dteDate + (7 - Weekday(dteDate))
-
Period = Format(FirstDayOfWeek, "mm/dd/yy") & "-" & Format(LastDayOfWeek, "mm/dd/yy")
-
End If
-
-
If WeekNumber > 1 And WeekNumber < 53 Then
-
FirstDayOfWeek = dteDate - (Weekday(dteDate) - 1)
-
LastDayOfWeek = dteDate - Weekday(dteDate) + 7
-
Period = Format(FirstDayOfWeek, "mm/dd/yy") & "-" & Format(LastDayOfWeek, "mm/dd/yy")
-
End If
-
-
If WeekNumber = 53 Then
-
WeekNumber = 52
-
FirstDayOfWeek = (dteDate - (Weekday(dteDate) - 1)) - 7
-
LastDayOfWeek = "12/31/" & Year(dteDate)
-
Period = Format(FirstDayOfWeek, "mm/dd/yy") & "-" & Format(LastDayOfWeek, "mm/dd/yy")
-
End If
-
Please use Code tags.
What you want is impossible. You have a range of dates, specifically the ones at the end of the year that lap over to the beginning of the next year, that can have more than one value but you give no way to decide between the two values. The following two records are from your example. They should either be both week number 1 or both be week number 52. They are the same type of dates but your result is inconsistent. It's arbitrary how you decide which number to assign it.
12/30/07 1 12/30/07-01/05/08
12/29/08 52 12/28/08-01/03/09
Hi, thanks for your reply Rabbit. So you mean there's no way I can calculate the weeknumber like this.
Sample: 12/30/07 1 12/30/07-01/05/08 , it calculated in this range is week number 1 because end of week is Saturday (01/05/08) and this is the first Saturday in January and it falls at least four days into the month such as (01/01/08, 01/02/08, 01/03/08, 01/04/08 and 01/05/08).
12/29/08 52 12/28/08-01/03/09, about this one it should calculate week number 52 even though (01/03/09) is still the first Saturday in January, however, it has only 3 days into that month (such as 01/01/09, 01/02/09, 01/03/09) , can't calculate week number 1 and should be calculated week number 52.
I tried too many ways but I couldn't get the result right. Does anyone else know please help, I'm very appreciated.
This should do it, I didn't test it yet. - iif(((Year(DateVariable) mod 4 = 0 AND Format(DateVariable, "y") >= 364) OR (Year(DateVariable) mod 4 <> 0 AND Format(DateVariable, "y") >= 363)) AND Weekday(DateSerial(Year(DateVariable), 12, 31)) >= 4, 52, 1)
After some testing, it looks like you should use: -
IIf(Format(DateVariable, "ww") = Format(DateSerial(Year(DateVariable), 12, 31), "ww") Or Format(DateVariable, "ww") = 1, IIf(Weekday(DateSerial(Year(DateVariable), 12, 31)) >= 4, 52, 1), IIf(Weekday(DateSerial(Year(DateVariable), 1, 1)) >= 5, Format(DateVariable, "ww") - 1, Format(DateVariable, "ww")))
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: CrystalDBA |
last post by:
I am using SQL Server 2000. I need to query my database for all the
contracts that came in during a certain time frame (user is prompted
for reportingperiodid).
Table - Periods
Fields -...
|
by: DD |
last post by:
Hi there,
I am working on a sql-query and I need to know the weeknumber of a given
date. Could anyone please help me with this.
Thanks in advance,
Arjen
|
by: Apple |
last post by:
I need to create a form call "Receipt" that contain field to calculate
payment - called " TotalPayment" = "PaymentFor" * "Period". In
"PaymentFor", I suppose to use a combo box for 5 items...
|
by: bjaj |
last post by:
Hi
I have made this msgbox to display the current Week number, but it
shows the wrong weekno.
Can anyone tell me why ?
msg = "WeekNumber: " & DatePart("WW", Date)
MsgBox msg
It shows...
|
by: Rustan |
last post by:
Hi
Im using GregorianCalendar to find out the current years week numbers.
When the user chooses a week number in a dropdown i want to show that week
in a table with the corresponding dates.
For...
|
by: PeterW |
last post by:
Hello,
I have a table that contains fields for WeekNumber, OilReceived and
OilRemaining.
WeekNum OilRecd OilRem
4 1200
5 1000 2000
6 1800
|
by: Longkhi |
last post by:
Hi Everybody.
I'm developing a dentist program, which contains a MonthCalender. I would like to select a specific weeknumber, when I select a weeknumber in the MC. I can show the weeknumbers by...
|
by: peetersb |
last post by:
Hi,
I want ot make functions like this:
int getFirtDayOfWeek(int weeknumber, int year);
int getLastDayOfWeek(int weeknumber, int year);
Firts I calculate the count of weeks like this:
...
|
by: shilpareddy2787 |
last post by:
Hello,
I have some total values, I want to calculate percenatge of these Total Values.
I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period.
...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
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: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
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: 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)...
| |