Re: COMMAND DAY
Posted in 1996
>Date: Wed, 15 May 1996 13:14:54 GMT >From: ida@kusza.edu.my >Subject: COMMAND DAY >X-Informix-List-Id: <list.9863> > >I just want to know a command to find the number of days for a certain month. >for example january 96 consist of 31 days feb consists of 28 days > >Comeey Feb 1996 had 29 days, actually... There is no standard function to determine the number of days in a particular month. Depending on which language you want to write the function in, and depending also on how you wish to specify the month, you can do it in a number of different ways. Basically, they will all resolve to variants of 'Subtract the DATE value for the 1st of the requested month from the DATE value for the 1st of the month following the requested month'. FUNCTION days_in_month(reqdate) DEFINE reqdate DATE DEFINE tmonth DATE DEFINE nmonth DATE DEFINE mm INTEGER DEFINE yy INTEGER -- Dissect requested date LET mm = MONTH(reqdate) LET yy = YEAR(reqdate) -- Determine 1st of this month LET tmonth = MDY(mm, 1, yy) -- Determine 1st of next month LET mm = mm + 1 IF mm > 12 THEN LET mm = 1 LET yy = yy + 1 END IF LET nmonth = MDY(mm, 1, yy) RETURN nmonth - tmonth END FUNCTION {days_in_month} This code has not been through a compiler -- take it as it is. Using DATETIME values gets harder; I'd probably end up converting to DATE values anyway, though it would be easier to add 1 UNITS MONTH to a DATETIME YEAR TO MONTH value. With minor changes, this could be made into a stored procedure. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>