OpenNTF.org - Get number of days for a given
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Get number of days for a given month (handles leap years) 
Rating:
Not Rated Yet 
Contributor:
Loren Lang 
Category:
Lotus Formula 
Type:
Example Code 
Notes Version:
R5.x 
Last Modified:
23 Nov 2004 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
This forumla will return the number of days in a given month for a given year, including a proper number of days for February in leap years. It assumes you have two fields on your form that hold the month and year.


I used this to generate an ending date (in a separate field) for a date range in which the user only selects the month and year from combo boxes.

Usage / Example
@If(Month="January":"March":"May":"July":"August":"October":"December";
31;
Month="April":"June":"September":"November";
30;
Month="February";
@If(@Modulo(@TextToNumber(Year);4)=0;
@If (@Modulo(@TextToNumber(Year);100)=0;
@If(@Modulo(@TextToNumber(Year);400)=0;
29;
28);
29);
28);
0);
 Comments
Posted by francesco marzolo on 11/23/2004 04:10:47 PMBefore I seen your code, I am thinking that the way was...
Month:=m; year:= y;
FirstDayThisMonth:=@date(1;Month;year);
FirstDayNextMonth:=@adjust(FirstDayThisMonth;0;1;0;0;0;0);
FirstDayNextMonth-FirstDayThisMonth
------------------
I wrote this now without a debug.
Sorry for mistakes, hope the idea is clear.
Francesco Marzolo
Posted by Loren Lang on 11/24/2004 07:01:47 AMI'll have to try that...
I'm relatively new to Notes programming and have never seen (much less used) the @Adjust function. I'm going to investigate that further. Thanks for the input.
Posted by Stan Rogers on 11/24/2004 12:24:36 PMIt would be closer to ....
Given a date "Date"
daysInMonth := @Day(@Adjust(@Adjust(@Adjust(Date;0;0;1-@Day(date);0;0;0);0;1;0;0;0;0);0;0;-1;0;0;0))
The innermost @Adjust gives you the first of the current month (good formula to have around for a lot of reasons). The next gives you the first of next month, the outermost gives you the last day of this month. The last day of the month is also the number of days in the month.
Posted by Christoph Schreiber on 05/15/2006 03:11:39 PMVery short version
REM Month := 05;
REM Year := 2006;
@Day(@Adjust(@Date(Year; Month; 1); 0; 1; -1; 0; 0; 0));
At first, I calculate the date Month/01/Year. Then, I add one month to the result (first of next month) and subtract one day (last of this month). Then, I extract the day of the calculated date.
 Add your comment!