Last day of the month??
Posted in 1996
> > Hi, > Is there any Informix lib function to get last day of the > month? or how do get that? could someone help? > > Thanks in advance. > > -Ramki > database xyz main define t_date date define p_date date define l_day integer # other stuff. # --- 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 # to get the last DATE of that month do: # --- start of addition 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 let t_date = '01/15/1994' let l_day = last_day(t_date) display 'The last day of the month containing ',t_date,' is ',l_day 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 -- _____________________________________________________________________________ Jack Parker - Hewlett Packard, DMD/IS Boise, Idaho, USA jparker@hpbs3645.boi.hp.com _____________________________________________________________________________ "I'm with the IRS, I'm here to help you" _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________