Re: [U2] Finding last day of month

2005-06-04 Thread Mark Baldridge
The original request was for a shortest code fragment. This likely meant as line count, but could have been execution time. I am using UniVerse 10.1.3 on a 1.7 GHz pentium. Here are some current timings. Except for test 0001 which is an empty FOR NEXT loop, to the left of the | is a hint of

Re: [U2] Finding last day of month

2005-06-03 Thread FFT2001
In a message dated 6/2/2005 9:40:08 PM Pacific Daylight Time, [EMAIL PROTECTED] writes: [EMAIL PROTECTED] wrote on 06/02/2005 10:34:09 PM: input oDate ; *format mmdd iDate = iconv(oDate,'dymd') loop until oconv(iDate+1,'dd) = 1 do iDate += 1 repeat lastDay = oconv(iDate,'dymd')

Re: [U2] Finding last day of month

2005-06-03 Thread FFT2001
In a message dated 6/2/2005 8:17:25 PM Pacific Daylight Time, [EMAIL PROTECTED] writes: That's an interesting approach, but it comes at the price of an extra ICONV, which is more expensive than a simple IF statement. Granted, the difference isn't significant for a small number of

Re: [U2] Finding last day of month

2005-06-03 Thread Stuart . Boydell
But your's takes more CPU cycles so there :) Smaller in opcode? or smaller in milliseconds? Ah Yeah, but now that you've challenged me, this one's smaller in size, op codes and presumably cpu. input oDate ; *format mmdd lastDayOfMonth =

Re: [U2] Finding last day of month

2005-06-03 Thread Marco Manyevere
Will, This was exactly my method, except I was adding 35 days (it could have been 30 as well) to the first day of the month to get to next month. I also dislike the lookup table idea i.e. 31,28,30,31,etc, the leap year or 12th month logic. Thanks for all the responses guys. [EMAIL

Re: [U2] Finding last day of month

2005-06-03 Thread Moderator
All, The Play Date has been moved to the U2-Community. - Charles Barouch, Moderator To sign up for U2-Community or any of our other lists: 1. U2-Users 2. U2-Community 3. RBSolutions 4. SBSolutions 5. U2-Users Digest 6. U2-Community Digest 7. RBSolutions Digest 8.

RE: [U2] Finding last day of month

2005-06-03 Thread Bob Witney
@listserver.u2ug.org Cc: Subject: Re: [U2] Finding last day of month Will, This was exactly my method, except I was adding 35 days (it could have been 30 as well) to the first day of the month to get to next month. I also

Re: [U2] Finding last day of month

2005-06-02 Thread Allen Egerton
From: Marco Manyevere [EMAIL PROTECTED] Hi, Given a date like 20040203, I want to return the last valid date for that month and year (20040229 in this case). What is the shortest code fragment to achieve this? Find the internal date of the first day of the next month, subtract 1, and convert

Re: [U2] Finding last day of month

2005-06-02 Thread Lembit Pirn
You can try ICONV(date,code) and check STATUS(). If status() returns other than 0 then date is valid Marco Manyevere wrote: Hi, Given a date like 20040203, I want to return the last valid date for that month and year (20040229 in this case). What is the shortest code fragment to achieve

RE: [U2] Finding last day of month

2005-06-02 Thread Bob Woodward
I might offer a small modification to your code snippet as noted below. BobW From: Marco Manyevere [EMAIL PROTECTED] Hi, Given a date like 20040203, I want to return the last valid date for that month and year (20040229 in this case). What is the shortest code fragment to achieve

Re: [U2] Finding last day of month

2005-06-02 Thread Timothy Snyder
Marco Manyevere [EMAIL PROTECTED] wrote on 06/02/2005 01:31:17 PM: Given a date like 20040203, I want to return the last valid date for that month and year (20040229 in this case). What is the shortest code fragment to achieve this? Ooh! A good old-fashioned programming challenge. I think

Re: [U2] Finding last day of month

2005-06-02 Thread Cliff Bennett
Hi, Marco. I always ICONV the first day of the next month, then subtract a day. For example: ANY.DATE = '02-03-2004' MO = ANY.DATE[1,2] YR = ANY,DATE[7,4] MO += 1 IF MO 12 THEN MO = 1 YR += 1 END EOM.DATE = ICONV(MO:'-01-':YR, 'D') - 1 This lends itself to a subroutine or function as

Re: [U2] Finding last day of month

2005-06-02 Thread Dianne Ackerman
That method can actually backfire, for example, if your starting date is 20040130, you'll end up on Feb 29 instead of Jan 31. What I would do is replace the day with 01 and add 1 to the month, then iconv and subtract 1 day. -Dianne Marco Manyevere wrote: Hi, Given a date like 20040203, I

RE: [U2] Finding last day of month

2005-06-02 Thread Perry Taylor
Here's how I do it... JJ = ICONV(THE.DATE, 'D') MO = OCONV(JJ, 'DM') YR= OCONV(JJ, 'DY') DAY=28 LOOP TRY = OCONV(ICONV(MO:'/':DAY+1:'/':YR, 'D'), 'DM') WHILE TRY = MO DO REPEAT LAST.DAY = MO:'/':DAY:'/':YR Perry Taylor -Original Message- From: Marco Manyevere [mailto:[EMAIL

RE: [U2] Finding last day of month

2005-06-02 Thread gerry-u2ug
same idea with a few less conversions cdate=20040203 yr=cdate[1,4] mn=cdate[5,2] if mn12 then mn+=1 else mn=1 ; yr+=1 edate=oconv(iconv(mn'R%2':'-01-':yr,D)-1,D) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Marco

RE: [U2] Finding last day of month

2005-06-02 Thread Kathleené M Bodine
0001: INPUT DATE 0002: USE.DATE = ICONV(DATE,D) 0003: MTH = OCONV(USE.DATE,DM) 0004: YR = OCONV(USE.DATE,DY4) 0005: IF MTH LT 12 THEN 0006: MTH += 1 0007: END ELSE 0008: MTH = 1 0009: YR += 1 0010: END 0011: NEW.DATE = ICONV(MTH:/01/:YR,D) - 1 0012: CRT OCONV(NEW.DATE,D) -Original

RE: [U2] Finding last day of month

2005-06-02 Thread Allen E. Elwood
are truly messing with my head today.and for the last weekGaaa Allen -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Dianne Ackerman Sent: Thursday, June 02, 2005 11:21 AM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Finding last day of month

RE: [U2] Finding last day of month

2005-06-02 Thread Ian McGowan
Need to take month mod 12, when adding... D=20040203 Y=D[1,4] M=D[5,2] M+=1 IF M12 THEN M=1;Y+=1 NEXT.M=ICONV(M:/01/:Y,D4/)-1 PRINT OCONV(NEXT.M,D4Y):OCONV(NEXT.M,DM):OCONV(NEXT.M,DD) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marco Manyevere

RE: [U2] Finding last day of month

2005-06-02 Thread Paul Sohn
] [mailto:[EMAIL PROTECTED] On Behalf Of Allen Egerton Sent: Thursday, June 02, 2005 10:57 AM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Finding last day of month From: Marco Manyevere [EMAIL PROTECTED] Hi, Given a date like 20040203, I want to return the last valid date for that month

RE: [U2] Finding last day of month

2005-06-02 Thread Norman Morgan
. === -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Allen Egerton Sent: Thursday, June 02, 2005 12:57 PM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Finding last day of month From: Marco Manyevere [EMAIL PROTECTED

Re: [U2] Finding last day of month

2005-06-02 Thread Don Verhagen
* User Supplied ISO Date UserDate= '20040203' UserDateYear= UserDate[1,4] + 0 UserDateMonth = UserDate[5,2] + 0 UserDateDay = UserDate[7,2] + 0 * First Day Of The Next Month NextMonthYear = UserDateYear + (IF (UserDateMonth + 1) 12 THEN 1 ELSE 0) NextMonthMonth = (IF

RE: [U2] Finding last day of month

2005-06-02 Thread colin.alfke
If it's for a UniData dictionary you can use the function LAST_DAY(date) that will return the last day of the month. I'm not sure if UniVerse has this function as well. Eg: 001: I 002: LAST_DAY(INVOICE.DATE) 003: D4 004: Last Day of Month 005: 15R

Re: [U2] Finding last day of month

2005-06-02 Thread Richard A. Wilson
, 2005 11:21 AM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Finding last day of month That method can actually backfire, for example, if your starting date is 20040130, you'll end up on Feb 29 instead of Jan 31. What I would do is replace the day with 01 and add 1 to the month, then iconv

RE: [U2] Finding last day of month

2005-06-02 Thread Allen E. Elwood
@listserver.u2ug.org Subject: RE: [U2] Finding last day of month If it's for a UniData dictionary you can use the function LAST_DAY(date) that will return the last day of the month. I'm not sure if UniVerse has this function as well. Eg: 001: I 002: LAST_DAY(INVOICE.DATE) 003: D4 004: Last Day

RE: [U2] Finding last day of month

2005-06-02 Thread Ed Clark
unidata has a LAST_DAY function? what version is that? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Thursday, June 02, 2005 2:22 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Finding last day of month If it's

RE: [U2] Finding last day of month

2005-06-02 Thread Rotella, Leon M.
Here's yet another way... END.OF.MONTH 0001 EDATES = 31:@FM:29:@FM:31:@FM:30:@FM:31:@FM:30:@FM:31:@FM:31:@FM: 30:@FM:31 :@FM:30:@FM:31 0002 PRINT INPUT DATE MMDD - : ; INPUT ODATE 0003 EYEAR = ODATE[1,4] 0004 EMONTH = ODATE[5,2] 0005 EDAY = EDATESEMONTH

RE: [U2] Finding last day of month

2005-06-02 Thread Ed Clark
Of [EMAIL PROTECTED] Sent: Thursday, June 02, 2005 2:22 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Finding last day of month If it's for a UniData dictionary you can use the function LAST_DAY(date) that will return the last day of the month. I'm not sure if UniVerse has this function as well

RE: [U2] Finding last day of month

2005-06-02 Thread Allen E. Elwood
@listserver.u2ug.org Subject: Re: [U2] Finding last day of month you cant just use mod(x,4) logic the following from some website (dont remember where/when I found it) *** The rule for leap years is that all years divisable by 4 are leap years, except those years divisable by 100. The exception

RE: [U2] Finding last day of month

2005-06-02 Thread colin.alfke
It's in my version 5 documentation - not sure when it was put in. There is also ADD_MONTHS, LAST_DAY, MONTHS_BETWEEN and NEXT_DAY. See Virtual Attribute Functions in chapter 5 Creating Virtual Attributes. Colin Alfke Calgary, Canada Where it's Sunny, no pouring rain, no wait it's just cloudy,

RE: [U2] Finding last day of month

2005-06-02 Thread James Canale, Jr.
This is documented back to at least UniData 5.2 and probably earlier than that though I don't have easy access to the old manuals. It is in the Using UniData manual in the Creating Virtual Attributes section. You may wish to search for Virtual Attribute Functions. HTH. Regards, Jim [snip]

Re: [U2] Finding last day of month

2005-06-02 Thread Richard A. Wilson
there in my years too. Just turned 49 last March. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Richard A. Wilson Sent: Thursday, June 02, 2005 12:29 PM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Finding last day of month you cant just use mod(x,4

RE: [U2] Finding last day of month

2005-06-02 Thread Allen E. Elwood
applications will be a zero wait state memory device. Beam me up Scotty! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Richard A. Wilson Sent: Thursday, June 02, 2005 1:38 PM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Finding last day of month 2100

RE: [U2] Finding last day of month

2005-06-02 Thread Stevenson, Charles
I use the method my dad taught me when I was a kid, cuz I couldn't remember Thiry days hath September Hold 2 fists side-by-side, forefingers of right left hand touching. Each knuckle and each valley between knuckles represents a month. Start at the left pinky knuckle and count off months. If

RE: [U2] Finding last day of month

2005-06-02 Thread Marilyn Hilb
Message- From: Stevenson, Charles [mailto:[EMAIL PROTECTED] Sent: Thursday, June 02, 2005 4:02 PM To: u2-users@listserver.u2ug.org Subject:RE: [U2] Finding last day of month I use the method my dad taught me when I was a kid, cuz I couldn't remember Thiry days hath September

RE: [U2] Finding last day of month

2005-06-02 Thread Bruce Nichol
Oh dear, Oh dear! What ever happend to : DATE = '' FOR I = 31 TO 28 STEP -1 IF OCONV(ICONV(I:rest of date,'D'),'D') = I:rest of date THEN DATE = I:rest of date EXIT END NEXT I IF DATE = '' THEN Come to screeching HALT Of course for the people with backward dates (!!!), the I:rest of

RE: [U2] Finding last day of month

2005-06-02 Thread Ross Morrissey
Aiming for SHORT (not clean, clear, or any of that other good stuff): PRINT D: ; INPUT D PRINT D[1,6]:MOD(D[5,2]+D[5,2]7,2)+30-(D[5,2]=2)*(2-MOD(D[1,4],4)#0) D?20040203 20040229 D?20030303 20030331 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marco

RE: [U2] Finding last day of month

2005-06-02 Thread Kieran Clulow
That incorrectly thinks 2100 is a leap. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ross Morrissey Sent: Friday, 3 June 2005 10:15 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Finding last day of month Aiming for SHORT (not clean, clear

Re: [U2] Finding last day of month

2005-06-02 Thread FFT2001
soapbox People! use the system why are you doing all this math in your program? The system knows what years are leap and what aren't. Let it do the work for you! /soapbox Will Johnson --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit

RE: [U2] Finding last day of month

2005-06-02 Thread Kieran Clulow
... or as a one line coding horror ;) 1 LAST.DAY = REPLACE(CHANGE('31,28,31,30,31,30,31,31,30,31,30,31',',',@AM),2;28+(NOT(MOD(( THISDATE[1,4]),4)) AND (NOT(MOD((THISDATE[1,4]),400)) OR MOD((THISDATE[1,4]),100(THISDATE[5,2]+0) --- u2-users mailing list u2-users@listserver.u2ug.org

Re: [U2] Finding last day of month

2005-06-02 Thread FFT2001
Ok smartass you say let's see you do it First of all, you can always get from the month you are in, to the next month by simply add 30 days to the middle of the month. And you never need to worry about leap years nor about 12th month logic Input Date ; * format mmdd Middleofthismonth

Re: [U2] Finding last day of month

2005-06-02 Thread FFT2001
In a message dated 6/2/05 7:07:42 PM Pacific Daylight Time, [EMAIL PROTECTED] writes: Input Date ; * format mmdd Middleofthismonth = date[1,6]:'15' I.Middle = Iconv(Middleofthismonth,'D') I.Next = I.Middle + 30 NextMonth = Oconv(I.NEXT,'D2-') FirstDayNextMonth =

Re: [U2] Finding last day of month

2005-06-02 Thread Timothy Snyder
[EMAIL PROTECTED] wrote on 06/02/2005 09:54:59 PM: Input Date ; *format mmdd NextMonth = Oconv(Iconv(date[1,6]:'15','D') + 30,'D2') I.LastDayPreviousMonth = Iconv(NextMonth[1,2]:'01':NextMonth[5,2],'D') + 1 That's an interesting approach, but it comes at the price of an extra ICONV,

RE: [U2] Finding last day of month

2005-06-02 Thread Allen E. Elwood
:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Thursday, June 02, 2005 7:46 PM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Finding last day of month In a message dated 6/2/05 7:07:42 PM Pacific Daylight Time, [EMAIL PROTECTED] writes: Input Date ; * format mmdd Middleofthismonth

Re: [U2] Finding last day of month

2005-06-02 Thread Timothy Snyder
[EMAIL PROTECTED] wrote on 06/02/2005 10:34:09 PM: input oDate ; *format mmdd iDate = iconv(oDate,'dymd') loop until oconv(iDate+1,'dd) = 1 do iDate += 1 repeat lastDay = oconv(iDate,'dymd') Not sure if it's worth bragging about - but mine's smaller (146 v. 161 bytes). This will

RE: [U2] Finding last day of month

2005-06-02 Thread Anthony Grant
Oh please, Kieran. That's overboard. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kieran Clulow Sent: Friday, 3 June 2005 11:43 AM To: u2-users@listserver.u2ug.org Subject: RE: [U2] Finding last day of month ... or as a one line coding horror ;) 1