View previous topic :: View next topic
|
Author |
Message |
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
Hi,
I have to find out the first Monday of a particular week given.
For instance if the week is 47 (input) of this year, then I would need the output as 11/21/2016.
Can anyone please help if we have a routine to find out ?. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
There is only one Monday in a week
As for what that day is, get Sunday from (week-1)*7, then add 1 to get Monday. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Quote: |
There is only one Monday in a week |
Sometimes it feels like there are more than one. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
COBOL does not have great date processing functions, so there is no routine to do what you want. You will need to write one yourself. And since you provided almost nothing about what you need in your post, the routine will have to be written by you.
Questions you did not answer in your post include:
- Will the week number always be for this year?
- How is the week number determined -- from Sunday? from Monday? from some other day?
- What happens when the year changes during the week (for example, in 2019 the first of January is on a Tuesday)?
- What if the week number comes in as something greater than 53?
Once you have a complete determination of the requirements, writing a routine is pretty easy -- convert the date for the Monday of week 1 to integer using the intrinsic function, add 7 times the week number to that value, then convert back to a date using the intrinsic function. That assumes you're only dealing with week numbers for a single year, of course. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
the only thing that the TS should have told is
if they use the ISO standard to handle the week number
if the TS organisation uses a different algorithm nothing we can say
anyway it is enough to determine the date of the monday of the first ISO week of a year
and after everything should be easy |
|
Back to top |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
Hi Robert,
To answer your questions,
Questions you did not answer in your post include:
- Will the week number always be for this year? - no it changes. it can be for different years.
- How is the week number determined -- from Sunday? from Monday? from some other day? - I do have a file where the week number is populated. This serves as an input for me.
- What happens when the year changes during the week (for example, in 2019 the first of January is on a Tuesday)? - In this case I should hold the value as 31/12/2018.
- What if the week number comes in as something greater than 53? - I do have a file as input which holds only valid values. So nothing would be greater than 53.
Sorry that I did not understand your point, "convert the date for the Monday of week 1 to integer using the intrinsic function, add 7 times the week number to that value, then convert back to a date using the intrinsic function". |
|
Back to top |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
Dear Akatsukami,
I went by your logic, "get Sunday from (week-1)*7, then add 1 to get Monday".
For ex: 47th week is from 21st Nov to 27th Nov. So I calculated it as,
(47-1)*7 = 322, then added 1,= 322+1 = 323. This 323rd day is Nov 18th which is Friday.
Please let me know if I am missing something here. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Why do you have to find a Monday? What will you use it for? What if a Monday is public holiday?
You were told that adding one to the date of the Sunday in the previous week would be the Monday in the current week. That also depends on which is your first day of the week. |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Here is a small rexx program to achieve what you want:
Code: |
/* rexx */
days = "Monday Tuesday Wednesday Thursday Friday Saturday Sunday"
numofweek = 05
dayofwk = wordpos( date(weekday), days )
basedate = date('base')
nextmondate = basedate - dayofwk + numofweek * 7 + 1
say 'day is : ' date(weekday,nextmondate,'base')
say 'date is : ' date('standard',nextmondate,'base') |
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Quote: |
Here is a small rexx program to achieve what you want: |
unfortunately it does NOT
it calculates the date of the monday of 5th week relative to the current week
as told before ...
given a year and a week number
the computation starts by finding out the date of the monday of the first week of the year
and according to the ISO numbering standard for the week
the first week of a year is the one which contains the thursday
and after that You can add 7 * week-number
see here for a discussion and a REXX snippet to convert dates to/from a ISO week representation
www.ibmmainframeforum.com/clist-rexx/topic3963.html?hilit=iso |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Quote: |
It calculates the date of the monday of 5th week relative to the current week |
Yes. That's correct. I misunderstood the requirement. |
|
Back to top |
|
|
|