What week of the year is it?
Recently a support case came in asking if there was an OCONV option to determine the week of the year of a passed date. OCONV won't do that, so I wrote a subroutine:
subroutine weekOfYear.sub(inDate, weekNo)
*
* Pass: inDate ( 5-digit internal date format )
* Return: weekNo ( 1-53 )
* Calculates which Sunday-Saturday week#
* within the year. Week 1 is only 7 days
* if January 1st is a Sunday.
*
if not(assigned(inDate)) then inDate=date()
if inDate matches "5n" else inDate=iconv(inDate,"d")
if inDate matches "5n" else inDate=date()
inYear=oconv(inDate,"dy")
begOfYear=iconv("1/1/":inYear,"d")
firstYearDay=oconv(begOfYear,"dw")
daysToSun=7-firstYearDay
weekNo=int(((oconv(inDate,"dj")-daysToSun)+6)/7)+(daysToSun>0)
return
As the comments state, you pass a date in Pick internal format, which has been a 5-digit number since May of 1995, and you receive a number from 1 to 53 indicating which week of the year contains that date. This assumes that the week you seek starts on a Sunday and ends on a Saturday. It will result in week 1 only being 7 days long if January 1st is a Sunday, and although popular perception thinks of a year being 52 weeks, there will always be a week 53 that contains December 31st at the bare minimum.
Anybody out there got anything to add or that they did differently? And more importantly, if you've done something similar that solves some other problem that you want to share with your Forum pals, please start a new thread and show us what you've got!!
------------------------------
Brian S. Cram
Principal Technical Support Engineer
Rocket Software
------------------------------
subroutine weekOfYear.sub(inDate, weekNo)
*
* Pass: inDate ( 5-digit internal date format )
* Return: weekNo ( 1-53 )
* Calculates which Sunday-Saturday week#
* within the year. Week 1 is only 7 days
* if January 1st is a Sunday.
*
if not(assigned(inDate)) then inDate=date()
if inDate matches "5n" else inDate=iconv(inDate,"d")
if inDate matches "5n" else inDate=date()
inYear=oconv(inDate,"dy")
begOfYear=iconv("1/1/":inYear,"d")
firstYearDay=oconv(begOfYear,"dw")
daysToSun=7-firstYearDay
weekNo=int(((oconv(inDate,"dj")-daysToSun)+6)/7)+(daysToSun>0)
return
As the comments state, you pass a date in Pick internal format, which has been a 5-digit number since May of 1995, and you receive a number from 1 to 53 indicating which week of the year contains that date. This assumes that the week you seek starts on a Sunday and ends on a Saturday. It will result in week 1 only being 7 days long if January 1st is a Sunday, and although popular perception thinks of a year being 52 weeks, there will always be a week 53 that contains December 31st at the bare minimum.
Anybody out there got anything to add or that they did differently? And more importantly, if you've done something similar that solves some other problem that you want to share with your Forum pals, please start a new thread and show us what you've got!!
------------------------------
Brian S. Cram
Principal Technical Support Engineer
Rocket Software
------------------------------
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.





