viewpoint-particle

Author Topic: Calculating the Week Number  (Read 344 times)

oradba4u

  • Newbie
  • *
  • Posts: 35
Calculating the Week Number
« on: July 16, 2017, 04:31:30 pm »
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

  • Pundit
  • *****
  • Posts: 786
    • Data & Stuff Inc.
Re: Calculating the Week Number
« Reply #1 on: July 16, 2017, 08:32:27 pm »
Might take a look here...

    http://winbatch.hpdd.de/

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

Jim

stanl

  • Pundit
  • *****
  • Posts: 650
Re: Calculating the Week Number
« Reply #2 on: July 17, 2017, 03:12:09 am »
one possibility

Code: Winbatch
#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

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


stanl

  • Pundit
  • *****
  • Posts: 650
Re: Calculating the Week Number
« Reply #4 on: July 17, 2017, 12:30:39 pm »
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

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
Re: Calculating the Week Number
« Reply #5 on: July 17, 2017, 01:42:53 pm »
Detlev's solution and the solution at the top of the Tech Support articular produces the ISO 8601 Standard week of the year. 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates