re: COMMAND DAY
Posted in 1996
########### # INFORMIX PROFESSIONAL SERVICES ####### # ## Denver, Colorado ###### # ### ================================================== ##### # #### File: %M% SCCS: %I% %P% #### # ##### Program: Month stuff ### # ###### Client: Demo ## # ####### Author: Dennis J. Pimple # ########### Date: %G% %U% # Determine number of days in the month # The MAIN is for testing purposes only MAIN DEFINE lmonth SMALLINT DEFINE lyear SMALLINT DEFINE ldays SMALLINT DEFINE txt CHAR(80) OPTIONS PROMPT LINE 15 CLEAR SCREEN WHILE TRUE LET txt = "Enter month (1-12) RET for TODAY, or INTERRUPT to quit:" PROMPT txt CLIPPED FOR lmonth IF lmonth IS NULL OR lmonth < 1 OR lmonth > 12 THEN LET lmonth = MONTH(TODAY) END IF LET txt = "Enter year (yyyy) RET for TODAY, or INTERRUPT to quit:" PROMPT txt CLIPPED FOR lyear IF lyear IS NULL THEN LET lyear = YEAR(TODAY) END IF IF lyear < 99 THEN LET lyear = 1900 + lyear END IF LET ldays = days_in_month(lmonth, lyear) LET txt = lmonth USING "&&", "/", lyear USING "&&&&", " has ", ldays USING "<<<&", " days in it." DISPLAY txt CLIPPED, "" AT 9,1 END WHILE END MAIN #---------------------------------------------------------------------# FUNCTION days_in_month(lmonth, lyear) # Arguments: Month (1,12), year (yyyy) in question # Purpose: Determine the number of days in lmonth/year # Returns: SMALLINT 1-31 #---------------------------------------------------------------------# DEFINE lmonth SMALLINT DEFINE lyear SMALLINT DEFINE bdate DATE DEFINE edate DATE DEFINE ldays SMALLINT # get the first day of the month LET bdate = MDY(lmonth,1,lyear) # get the first day of the next month IF lmonth = 12 THEN LET lmonth = 1 LET lyear = lyear + 1 ELSE LET lmonth = lmonth + 1 END IF LET edate = MDY(lmonth,1,lyear) LET ldays = edate - bdate RETURN ldays END FUNCTION # days_in_month(lmonth, lyear) The condensed version would be: IF lmonth = 12 THEN LET ldays = MDY(1,1,lyear + 1) - MDY(lmonth,1,lyear) ELSE LET ldays = MDY(lmonth + 1,1,lyear) - MDY(lmonth,1,lyear) END IF Or you could SELECT from a table with a date column: SELECT MDY(MONTH(date_column) + 1,1,YEAR(date_column)) - MDY(MONTH(date_column),1,YEAR(date_column)) FROM table WHERE MONTH(date_column) < 12 UNION SELECT MDY(1,1,YEAR(date_column) + 1) - MDY(MONTH(date_column),1,YEAR(date_column)) FROM table WHERE MONTH(date_column) = 12 aren't you sorry you asked? //////////////// ======================================================= ////////// // Dennis J. Pimple Informix Software, Inc. ////// / /// Principal Consultant 5299 DTC Blvd Suite 740 ///// // //// dennisp@informix.com Englewood CO 80111 //// // ///// /// // ////// recept: 303-850-0210 // // /////// direct: 303-740-5611 Opinions expressed are mine, / /////////// fax: 303-843-6408 and do not necessarily //////////////// http://www.informix.com reflect those of my employer