View previous topic :: View next topic
|
Author |
Message |
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
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 |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1205 Location: Dublin, Ireland
|
|
|
|
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 |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
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 |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
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 |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1205 Location: Dublin, Ireland
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
Try removing this line of code. Always do the calculation.
Code: |
if DayOfWeek < 6 then |
|
|
Back to top |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
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
|
|
Back to top |
|
|
Willy Jensen
Active Member
Joined: 01 Sep 2015 Posts: 734 Location: Denmark
|
|
|
|
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 |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
Yes, thanks.. it's done. |
|
Back to top |
|
|
|