Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
abdulrafi

Active User

Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

 Posted: Fri Nov 25, 2016 3:24 pm    Post subject: How to find the first monday of the week. 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 ?.

Akatsukami

Global Moderator

Joined: 03 Oct 2009
Posts: 1789
Location: Bloomington, IL

 Posted: Fri Nov 25, 2016 6:08 pm    Post subject: 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.
Terry Heinze

JCL Moderator

Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

Posted: Fri Nov 25, 2016 8:08 pm    Post subject:

 Quote: There is only one Monday in a week

Sometimes it feels like there are more than one.
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8561
Location: Dubuque, Iowa, USA

 Posted: Fri Nov 25, 2016 9:54 pm    Post subject: 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.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10700
Location: italy

 Posted: Fri Nov 25, 2016 10:11 pm    Post subject: Reply to: How to find the first monday of the week. 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
abdulrafi

Active User

Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

 Posted: Mon Nov 28, 2016 10:17 am    Post subject: 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".
abdulrafi

Active User

Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

 Posted: Mon Nov 28, 2016 10:31 am    Post subject: 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.
Bill Woodger

Moderator Emeritus

Joined: 09 Mar 2011
Posts: 7312
Location: Inside the Matrix

 Posted: Mon Nov 28, 2016 11:43 am    Post subject: Reply to: How to find the first monday of the week. 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.
mistah kurtz

Active User

Joined: 28 Jan 2012
Posts: 310
Location: Room: TREE(3). Hilbert's Hotel

Posted: Mon Nov 28, 2016 7:29 pm    Post subject:

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')
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10700
Location: italy

Posted: Mon Nov 28, 2016 8:28 pm    Post subject: Reply to: How to find the first monday of the week.

 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

http://www.ibmmainframeforum.com/clist-rexx/topic3963.html?hilit=iso
mistah kurtz

Active User

Joined: 28 Jan 2012
Posts: 310
Location: Room: TREE(3). Hilbert's Hotel

Posted: Mon Nov 28, 2016 9:51 pm    Post subject:

 Quote: It calculates the date of the monday of 5th week relative to the current week

Yes. That's correct. I misunderstood the requirement.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Java Batch launcher JVMPRC86 does not... harisukumaran IBM Tools 2 Wed Apr 15, 2020 12:37 am Adding FIND to ISPF Panel display of ... Harold Barnes TSO/ISPF 3 Mon Oct 07, 2019 5:46 pm Add week number to a file name or rep... tejdeep0274 JCL & VSAM 2 Thu Jan 03, 2019 6:49 am Find out which PSB is currently sched... Andi1982 IMS DB/DC 0 Mon Sep 24, 2018 3:16 pm How to find if segment is read in any... Priyanka AR IMS DB/DC 12 Thu Sep 20, 2018 1:34 pm

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us