Re: Last day of the month??
Posted in 1996
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
At 6:30 PM 2/8/96, Ramki Natesan wrote: >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 Ramki, Here's a function where I set global variables to the 1st and last day of the current month. For the last day of the month I set an Informix date variable to the 1st day of the next month. Then I just subtract 1 from the date which gives you the last day of the current month without having to know the number of days in the month, leap year status, etc. You'll note that all my code treats years using all 4 digits! You should be able to use and modify the code below for your purposes. I probably shouldn't convert to a string and then back to an integer, but I think I ported this to 4GL from some old C code where I used a similar technique -- don't fix it if it ain't broke! There are probably more elegant coding techniques and possibly other built-in functions that could be used -- I'd like to see those as well. Hope you find this useful. Darrell ###################################################################### # function set_default_dates() # # Set global g_start_date and g_end_date equal to 1st and last day # of this month. ###################################################################### function set_default_dates() define this_day date, next_month date, mon_int integer, day_str char(10), yr_int integer let this_day = today let day_str = this_day using "mm/dd/yyyy" let mon_int = day_str[1,2] ### get month as integer let yr_int = day_str[7,10] ### get year as integer ### first day of this month below let day_str = mon_int using "&&", "/01/", yr_int using "&&&&" let g_start_date = day_str ### now have 1st of this month as DATE let mon_int = mon_int + 1 ### get next month if mon_int = 13 then let mon_int = 1 ### if 13, then jan let yr_int = yr_int + 1 ### increment year as well end if ### first day of next month below let day_str = mon_int using "&&", "/01/", yr_int using "&&&&" let next_month = day_str ### 1st of next month as DATE let g_end_date = next_month - 1 ### give last day of this month end function ## set_default_dates() **----------------------------------------------** || Darrell S. Thacher darrell@gteens.com || || IntegriSoft, Inc. 817-430-8410 (voice) || || 817-430-4495 (fax) || **----------------------------------------------**