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

Relational operator compare date range with today


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Wed Feb 06, 2019 6:19 pm
Reply with quote

Hi,
I want to compare whether today falls within a date range of DST1 & DST2 ?

If satisfy, then set 5 else set 6.

today = Date('Base')
DST1= 737127
DST2= 737365

if X(today >= DST1 & today <= DST2)
this is not working which I am trying
Thanks
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Wed Feb 06, 2019 6:30 pm
Reply with quote

Code:
if X(today >= DST1 & today <= DST2)


What is the X function?

Do you mean
Code:
if (today >= DST1 & today <= DST2)
??

Date('Base') is returning 737005 today which falls outside the range and you should then return 6.

Garry.
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Wed Feb 06, 2019 6:55 pm
Reply with quote

Yes, I mean to compare
if (today >= DST1 & today <= DST2)

I think to put the result into X, don't need X.

If it satisfies, then need to setup with some value else some other value.

Thanks
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Wed Feb 06, 2019 7:14 pm
Reply with quote

Yes, I tried with

if today >= DST1 & today <= DST2 then say "5"
if today < DST1 & today > DST then say "6"

but this case returns with "0" not 5 or 6.

Thanks
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Wed Feb 06, 2019 7:17 pm
Reply with quote

For your 2nd test you should use OR not AND - it can't be both < and > .

But why not
Code:
if today >= DST1 & today <= DST2 then say "5"
              else say "6"


Garry
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Wed Feb 06, 2019 7:46 pm
Reply with quote

It may just be me, but my brain freezes with multiple ors (>= <=) along with ands (&) included.

I find this much easier to understand.

Note: If this is you universal time offset / daylight savings time solution,
then it will require maintenance every year.

Code:
/* REXX */
TODAY = DATE('BASE')
DST1= 737127
DST2= 737365
SELECT
  WHEN TODAY < DST1 THEN OFFSET = 5
  WHEN TODAY > DST2 THEN OFFSET = 5
  OTHERWISE OFFSET = 6
END
SAY TODAY OFFSET
EXIT
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Wed Feb 06, 2019 7:49 pm
Reply with quote

yes, it's working fine now. Thanks

in this case it returns "6" which is true.
so how to pass this value to the main module based on the value return in this ?

Thanks
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Wed Feb 06, 2019 8:08 pm
Reply with quote

daveporcelan wrote:

Code:
/* REXX */
TODAY = DATE('BASE')
DST1= 737127
DST2= 737365
SELECT
  WHEN TODAY < DST1 THEN OFFSET = 5
  WHEN TODAY > DST2 THEN OFFSET = 5
  OTHERWISE OFFSET = 6
END
SAY TODAY OFFSET
EXIT

With the SELECT being used like that I can't see it working correctly. When you use SELECT it only drops down to the next SELECT option if none of the above have been satisfied.

So if TODAY is less than DST1 then there will be no further checking performed so TODAY could be less than both DST1 and DST2 yet still set the OFFSET to 5
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Wed Feb 06, 2019 8:26 pm
Reply with quote

I will respond to three things at once.

First, my logic was slightly flawed (only in the OFFSET value). Corrected exec is below.

Second, Expat sure it works. Take the exec below (corrected) and set TODAY value manually. The OTHERWISE is only hit when TODAY is in the range.

Third, Max, the EXIT statement returns the value of OFFSET back to the calling program.

Code:
/* REXX */
TODAY = DATE('BASE')
DST1= 737127
DST2= 737365
SELECT
  WHEN TODAY < DST1 THEN OFFSET = 6
  WHEN TODAY > DST2 THEN OFFSET = 6
  OTHERWISE OFFSET = 5
END
SAY TODAY OFFSET
EXIT (OFFSET)
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Wed Feb 06, 2019 11:06 pm
Reply with quote

Thanks a lot, it's working fine.
one more issue I am facing while calculating DST1:

year = 2019
DST1 = Date('Base', year'0301', 'Standard')
DayOfWeek = DST1//7
if DayOfWeek < 6 then
DST1 = DST1 + 13 - DayOfWeek

Here I don't want to hard code the year in the code, instead I want to pass the year automate, so that I should not change the code everytime for the next year.

2nd: while calculating the DST1: it is the 2nd sunday of march every year.
while calculating, if the 1st day of march is sunday for any year(i.e., 2020), then it is not calculating the 2nd sunday, instead it is giving 1st sunday only.

If you have any suggestion, please let me know.
Thanks
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Wed Feb 06, 2019 11:43 pm
Reply with quote

Try removing this line of code. Always do the calculation.

Code:
if DayOfWeek < 6 then
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Thu Feb 07, 2019 12:34 pm
Reply with quote

Thanks for the advice, i removed the condition, now it's working fine.

Right now I am passing year as hard coded as below, can it be possible to fetch the only current year from somewhere or any command which can be fetched only current YYYY ?

year = 2019
DST1 = Date('Base', year'0301', 'Standard')

Thanks
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Feb 07, 2019 12:44 pm
Reply with quote

daveporcelan wrote:

Second, Expat sure it works. Take the exec below (corrected) and set TODAY value manually. The OTHERWISE is only hit when TODAY is in the range.

Yeah, must have been having a brain job yesterday, now after a better look

icon_redface.gif
Back to top
View user's profile Send private message
Willy Jensen

Active Member


Joined: 01 Sep 2015
Posts: 712
Location: Denmark

PostPosted: Thu Feb 07, 2019 2:55 pm
Reply with quote

Quote:
fetch the only current year from somewhere

You are already using Date('S') so you must have noticed that the left 4 bytes is the current year? So "yyyy=Left(Date('s'),4)" will do the trick. Or "Parse value date('s') with yyyy +4 mm +2 dd" if you want the month- and date numbers too.
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Thu Feb 07, 2019 4:51 pm
Reply with quote

Yes, thanks.. it's done.
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top