Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to find the first monday of the week.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

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

PostPosted: Fri Nov 25, 2016 6:08 pm    Post subject:
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: 1238
Location: Richfield, MN, USA

PostPosted: Fri Nov 25, 2016 8:08 pm    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Fri Nov 25, 2016 9:54 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

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

PostPosted: Mon Nov 28, 2016 10:17 am    Post subject:
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: 135
Location: Coimbatore

PostPosted: Mon Nov 28, 2016 10:31 am    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7234

PostPosted: Mon Nov 28, 2016 11:43 am    Post subject: Reply to: How to find the first monday of the week.
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: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Mon Nov 28, 2016 7:29 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Nov 28, 2016 8:28 pm    Post subject: Reply to: How to find the first monday of the week.
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

http://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: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Mon Nov 28, 2016 9:51 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Find out a active PGM jpsager JCL & VSAM 10 Fri Oct 07, 2016 4:32 pm
No new posts How to find a CICS resource used in C... Arunkumar Chandrasekaran CICS 8 Thu Sep 29, 2016 1:45 pm
No new posts how to find clist's or view library Andrew Hsia CLIST & REXX 4 Tue Jun 28, 2016 6:07 pm
No new posts How to find jobs that are in schedule... anilkumar922 All Other Mainframe Topics 5 Tue Jun 28, 2016 10:01 am
This topic is locked: you cannot edit posts or make replies. how to find if file is empty or not. abdulrafi DFSORT/ICETOOL 5 Tue May 17, 2016 4:39 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us