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 the following is simpler and, because it uses half as many date conversions, will burn fewer CPU cycles than your method. INPUT ORIG.DATE YEAR = ORIG.DATE[1,4] MONTH = ORIG.DATE[5,2] MONTH += 1 IF MONTH EQ 13 THEN MONTH = 1; YEAR += 1 NEW.DATE.I = ICONV(MONTH:'/01/':YEAR, 'D') - 1 NEW.DATE = CHANGE(OCONV(NEW.DATE.I, 'DYMD'), ' ', '') CRT NEW.DATE This may need to be modified if your default date convention is not MM/DD/YY. It also assumes that the input date is in the correct format. Tim Snyder Consulting I/T Specialist , U2 Professional Services North American Lab Services DB2 Information Management, IBM Software Group [EMAIL PROTECTED] ------- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/