Re: Programming using 4GL
Posted in 1993
Ruchi Patel Writes > >Is there any way I can find out maximum days for the current month? > >e.g 4/5/93 - April has 30 days The problem of calculating the number of days in the month can be solved using SQL. The solution would be more simple if it wasn't for December but here goes :- SELECT date1, DAY( MDY( month( date1 ) + 1,1, YEAR( date1))-1) Days_In_Month FROM datetab WHERE MONTH(date1) != 12 UNION SELECT date1, DAY( MDY(1,1,YEAR( date1)+1)-1) FROM datetab WHERE MONTH(date1) = 12 The rationale behind this is as follows :- 1. Calculate the first day of the following month. 2. Subtract 1 from that date. 3. Extract the day portion of this calculated date. 4. Act differently for December because of the year change. This should give a correct solution for any given date. Providing that the Informix date algorithms are correct :-) And just for Bill Foote the output for various suspect dates is as follows :- date1 days_in_month 01/02/1600 29 01/02/1990 28 01/02/1991 28 01/02/1992 29 01/02/2000 29 01/02/2400 29 My understanding of the leap year algorithm was that a leap year is Any year divisible by 4 and not divisible by 400. I didn't know about the 2000 year thing but it appears that Informix didn't know about the 400 year thing. Regards Steve -- ----------------------------------------------------------------------------- Steve Weet - European Mis - Motorola Cellular Subscriber Group Beechgreen Court, Chineham, Basingstoke, HANTS England. Phone : +44 (0)256 790154 E-Mail stevew@chineham.euro.csg.mot.com Fax : +44 (0)256 817481 Mobile : +44 (0)850 335105 Post : w10075