This algorithm is redundant and also fails to take into account the Boolean 
nature of the terms and thus adds extra unneeded op codes in the compare to 0 
and compare to 1 steps.  Below is the equivalent

BEGIN CASE
   CASE MOD(YEAR,400) ;LEAP.YEAR = TRUE
   CASE MOD(YEAR,100) ;LEAP.YEAR = FALSE
   CASE MOD(YEAR,4) ;LEAP.YEAR = TRUE
END CASE


* Leap year algorithm to detect if today is a leap year
EAR = OCONV(TODAY,"DY")
F MOD(YEAR,4) = 0 THEN
  IF MOD(YEAR, 100) = 0 THEN
     IF MOD(YEAR, 400) = 0 THEN LEAP.YEAR = 1 ELSE LEAP.YEAR = 0
  END ELSE LEAP.YEAR = 1
ND ELSE LEAP.YEAR = 0





-----Original Message-----
From: Daniel McGrath <dmcgr...@rocketsoftware.com>
To: U2 Users List <u2-users@listserver.u2ug.org>
Sent: Wed, Dec 7, 2011 8:02 am
Subject: Re: [U2] End of Month date routine


Perfectly fine except if you need to run this is a very large loop (such as 
atch processing 100 million records - although it only adds about 1.5 mins on 
y machine).
The modulo method takes (roughly) 54% the execution time of ICONV. This would 
be 
ecause of the extra processing ICONV has to do internally as well as the string 
oncatenation and memory allocation from "Feb 29":YEAR
Just something to keep in the back of the mind.
* Date Conversion to detect if today is a leap year
EAR = OCONV(TODAY,"DY")
EST = ICONV("Feb 29":YEAR,"D")
EAP.YEAR = (STATUS() = 0)
Vs
* Leap year algorithm to detect if today is a leap year
EAR = OCONV(TODAY,"DY")
F MOD(YEAR,4) = 0 THEN
  IF MOD(YEAR, 100) = 0 THEN
     IF MOD(YEAR, 400) = 0 THEN LEAP.YEAR = 1 ELSE LEAP.YEAR = 0
  END ELSE LEAP.YEAR = 1
ND ELSE LEAP.YEAR = 0
-----Original Message-----
rom: u2-users-boun...@listserver.u2ug.org 
[mailto:u2-users-boun...@listserver.u2ug.org] 
n Behalf Of David A. Green
ent: Wednesday, December 07, 2011 8:25 AM
o: 'U2 Users List'
ubject: Re: [U2] End of Month date routine
YEAR = OCONV(PASS.DATE, "DY")
EST = ICONV("Feb 29 ":YEAR, "D")
EAP.YEAR = (STATUS() = 0)
David A. Green
480) 813-1725
AG Consulting
-----Original Message-----
rom: u2-users-boun...@listserver.u2ug.org
mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Daniel McGrath
ent: Tuesday, December 06, 2011 4:22 PM
o: U2 Users List
ubject: Re: [U2] End of Month date routine
Leap years are a little more complex than MOD(YEAR,4)
>From http://en.wikipedia.org/wiki/Leap_years#Algorithm
if year modulo 4 is 0
  then
      if year modulo 100 is 0
          then
              if year modulo 400 is 0
                  then
                      is_leap_year
              else
                  not_leap_year
      else is_leap_year
lse not_leap_year

-----Original Message-----
rom: u2-users-boun...@listserver.u2ug.org
mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of John Hester
ent: Tuesday, December 06, 2011 4:16 PM
o: U2 Users List
ubject: Re: [U2] End of Month date routine
Your method is also the way I've always done it, but an alternate method just 
ame to mind:
MONTH = OCONV(DATE, 'DM')
EAR = OCONV(DATE, 'D Y[Z4]')
EAP = MOD(YEAR, 4) = 0
ONTHS = ''
ONTHS<1> = 31
ONTHS<2> = 28 + LEAP
ONTHS<3> = 31
ONTHS<4> = 30
ONTHS<5> = 31
ONTHS<6> = 30
ONTHS<7> = 31
ONTHS<8> = 31
ONTHS<9> = 30
ONTHS<10> = 31
ONTHS<11> = 30
ONTHS<12> = 31
AST.DAY = MONTHS<MONTH>
Not very concise, but you can tell at a glance how many days your dealing with. 
 

----Original Message-----
rom: u2-users-boun...@listserver.u2ug.org
mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Holt, Jake
ent: Tuesday, December 06, 2011 2:34 PM
o: U2 Users List
ubject: Re: [U2] End of Month date routine
Someone has probably already suggested one like this but I use:
DATE = ICONV("2-11-11",'D')
ONTH = OCONV(DATE,"DM")
EAR = OCONV(DATE,"DY")
ONTH += 1
F MONTH > 12 THEN
ONTH = 1
EAR += 1
ND
LAST.DAY = ICONV(MONTH:"/1/":YEAR,'D')-1 
_______________________________________________
2-Users mailing list
2-us...@listserver.u2ug.org
ttp://listserver.u2ug.org/mailman/listinfo/u2-users
______________________________________________
2-Users mailing list
2-us...@listserver.u2ug.org
ttp://listserver.u2ug.org/mailman/listinfo/u2-users
_______________________________________________
2-Users mailing list
2-us...@listserver.u2ug.org
ttp://listserver.u2ug.org/mailman/listinfo/u2-users
______________________________________________
2-Users mailing list
2-us...@listserver.u2ug.org
ttp://listserver.u2ug.org/mailman/listinfo/u2-users

_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to