Calculating the Week Number

Started by oradba4u, July 16, 2017, 04:31:30 PM

Previous topic - Next topic

oradba4u

All:
Is there any way to accurately calculate the week number for any given year?
For example, what is the week number that July 27, 2007 is in?
Can it be calculated for future dates as well?
If the year starts on a Saturday or Sunday is that considered week 1?
Do all years have 52 week numbers?

I know nothing about this, and am curious. I also want to write a winbatch program that calculates this (if possible)

Any help is greatly appreciated

Curious in Georgetown

JTaylor

Might take a look here...

    http://winbatch.hpdd.de/

Didn't look for your specific need but might be there.

Jim

stanl

one possibility

Code (WINBATCH) Select

#DefineFunction weeknumber(d)
   oXL = CreateObject("Excel.Application")
   oXL.Visible = 0 ;change to 0 after testing that it works
   retval=oXL.WorksheetFunction.weeknum(d)
oXL=0
Return(retval)
#EndFunction


message("",weeknumber("4/16/2020")  ;should return 16, assumes week begins on Sunday

Of course there are several vba calculations you  and some issues over using weeknum() or ISOweeknum. However, I would stick with Jim's suggestion for a pure WB solution.


td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

to clarify or further muddle:

oXL.WorksheetFunction.weeknum(d,2) ; assumes Monday as first day of week

oXL.WorksheetFunction.weeknum(d,21) ; ISO 8601 Standard, assumes Monday and week 1 must contain the first Thursday.

td

Detlev's solution and the solution at the top of the Tech Support articular produces the ISO 8601 Standard week of the year. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade