WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: oradba4u on July 16, 2017, 04:31:30 PM

Title: Calculating the Week Number
Post by: oradba4u 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
Title: Re: Calculating the Week Number
Post by: JTaylor 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
Title: Re: Calculating the Week Number
Post by: stanl on July 17, 2017, 03:12:09 AM
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.

Title: Re: Calculating the Week Number
Post by: td on July 17, 2017, 05:57:17 AM
Detlev's solution in the Tech Database:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Time~-~Timer~and~Date~Functions+Current~Week~of~the~Year.txt (http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Time~-~Timer~and~Date~Functions+Current~Week~of~the~Year.txt)
Title: Re: Calculating the Week Number
Post by: stanl 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.
Title: Re: Calculating the Week Number
Post by: td 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.