View previous topic :: View next topic
|
Author |
Message |
akshaiya
New User
Joined: 17 Sep 2005 Posts: 49
|
|
|
|
how to find last saturday and sunday of every month....
Can anyone give me the logic to include in cobol. |
|
Back to top |
|
|
parikshit123
Active User
Joined: 01 Jul 2005 Posts: 269 Location: India
|
|
|
|
Hi,
To add to that, complexity of leap years also needs to be taken into consideration.!
Its really a tough problem. At least not a cake walk for sure. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Here's one possibility:
Set up a wrk date CCYYMMDD.
Move your date to wrk date.
Add 1 to wrk-mm.
move 01 to wrk-dd.
compute int-date = function (integer of date (wrk-date)) - 1
int-date now has the int for the last day of your month
divide int-date by 7 giving ws-dummy-fld remainder ws-rem
If ws-rem = 0 it's a sunday; if 1 it's a mon; etc.
subtract ws-rem from int-date
That gives you the int for the last sunday in the month.
Then do a function (date of integer) for int-date. That gives you the CCYYMMDD for the last sunday. Then subtract 1 from sunday's DD to get the last Saturday of the month date.
Not sure of the syntax of the date functions but the logic looks OK. |
|
Back to top |
|
|
hikaps14
Active User
Joined: 02 Sep 2005 Posts: 189 Location: Noida
|
|
|
|
Hi ,
I hav also 1 SOL.
if u want to find all end of month sat. sun of whole year .
start with first day of year .
Logic:
1.Find out DATE of first saturday of month.
2.keep on adding 7 to its date and keep on checking with with no. of days left for End month .
if its less than 7 and Gr than 0 then we are at end sat and sun,
if its more than 7 then add 7 go to start of loop again .
it its equal to zero (sat is itself last day of month )
then we can subtract 6 and get last sun .
but for this code u need to cal. no. of days in that month in advance .
then only u can compare .
i hope u get this .
Thanks ,
Kapil. |
|
Back to top |
|
|
|