Bob Basketts last day function
Posted in 1994
all, I didn't realize it at the time we mailed, but Bob added a very nice twist to my last_day() function. In his version you pass in any date and get back the last day of THAT month. Here is that version along with demo code. main define t_date date define p_date date define l_day integer define yr integer # to get year define mnth integer # to get month define strg char(10) # intermediate let t_date = '01/31/1994' let l_day = last_day(t_date) display 'The last DAY of the month containing ',t_date,' is ',l_day let yr=YEAR(t_date) let mnth=MONTH(t_date) let strg= mnth using "##", "/", l_day USING "##", "/", yr USING "####" let p_date = DATE(strg) display 'The last DATE of the month containing ',t_date,' is ',p_date end main # Get the last day of the month. FUNCTION last_day(_current) define _current date DEFINE ld DATE, dn INTEGER # what day number is today? LET dn = DAY(_current) # subtract that many days yields last day last month. # add 1 day gives first day this month # add 1 month gives first day next month # subtract 1 day gives last day this month. # this is different from last_day last month + 1 month --> 30 vs 31. LET ld = (_current - dn UNITS DAY + 1 UNITS DAY ) + 1 UNITS MONTH - 1 UNITS DAY # get the day out of that and return. RETURN DAY(ld) END FUNCTION cheers j. _____________________________________________________________________________ Jack Parker | Hewlett Packard, BSMC Boise, Idaho, USA| BEER jparker@hpbs3645.boi.hp.com | It's not just for breakfast anymore. _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________