IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to find the first monday of the week.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Fri Nov 25, 2016 3:24 pm
Reply with quote

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
View user's profile Send private message
Akatsukami

Global Moderator


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

PostPosted: Fri Nov 25, 2016 6:08 pm
Reply with quote

There is only one Monday in a week icon_razz.gif

As for what that day is, get Sunday from (week-1)*7, then add 1 to get Monday.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


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

PostPosted: Fri Nov 25, 2016 8:08 pm
Reply with quote

Quote:
There is only one Monday in a week

Sometimes it feels like there are more than one. icon_smile.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Nov 25, 2016 9:54 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Nov 25, 2016 10:11 pm
Reply with quote

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
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Mon Nov 28, 2016 10:17 am
Reply with quote

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
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Mon Nov 28, 2016 10:31 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Mon Nov 28, 2016 11:43 am
Reply with quote

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
View user's profile Send private message
mistah kurtz

Active User


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

PostPosted: Mon Nov 28, 2016 7:29 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Nov 28, 2016 8:28 pm
Reply with quote

Quote:
Here is a small rexx program to achieve what you want:

unfortunately it does NOT icon_cool.gif

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
View user's profile Send private message
mistah kurtz

Active User


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

PostPosted: Mon Nov 28, 2016 9:51 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
No new posts Find the occurrence of Key Field (Par... DFSORT/ICETOOL 6
No new posts Find a record count/numeric is multip... COBOL Programming 1
No new posts Need to find a specific STRING COBOL Programming 11
Search our Forums:

Back to Top