Re: historical dates
Posted in 1996
Jason Wickline (jwicklin@richland.cc.il.us) wrote: : Is there a "easy" way to get information between two dates that are : inputed by the user. As well as the same information for 1 year prior to : the input dates. : : simply I want to get information between beg_date and end_date : as well as same time frame 1 year prior. : : subtracting 365 won't work because of leap years. How do you want to handle Feb 29th? A year ago becomes Feb 28 or March 1? For most cases, you could do this: FUNCTION year_ago( date_val ) DEFINE date_val DATE, new_date DATE LET new_date = date_val - 365 IF DAY(new_date) != DAY(date_val) THEN LET new_date = new_date - 1 END IF RETURN new_date END FUNCTION If the days of the month don't match, you know you've crossed over a leap day. So, subtract one to adjust. The way this will work with Feb 29, is you subtract 365, giving you March 1. Since 1 (Mar) <> 29 (Feb) you subtract 1 and get Feb 28. So, 02/29/96 --> 02/28/95 Also a "year ago" will never land on Feb 29th. 02/28/97 --> 02/28/96 03/01/97 --> 03/01/96 I suppose you could do some month/day checks for these conditions using the MONTH() and DAY() routines if you need to. -- __________________________________________________________________________ Joel Schumacher JCPenney Co. - UNIX Network Systems jschumac@uns-dv1.jcpenney.com 12700 Park Central Pl (972) 591-7543 Dallas TX 75251