How to get the number of days in a Month

How can I determine or know how many days has a month of a date.

Example:

2016-01

2015-12

2011-10

I know how to calculate differences between dates using DATE, but I don’t have idea of doing this.

The principal reason to wanna do is, that Theres months with 30 days, 31 days (February 28 days and 29 days).
So this is the reason, know how many days have a month, based on year,month.

1. Year
2. Month
3. Day

And at now, I’m doing as follows:

1. In Month popupMenu I have this rows: 1,2,3,4,5,6,7,8,9,10,11,12

So If Row 2 is Selected then
in popupDay Add this rows: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29

Else
in popupDay Add this rows: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31

``````function daysinMonth(d as date)  as integer // full date of month in question
d.day=1
d.month=d.month+1
d.day=d.day-1
return d.day
end function``````

Just keep in mind that Dave’s function will modify the given date. If you don’t want to do that, prefix this rest of his code with

``d = new Date( d )``

[quote=274499:@Dave S]``` function daysinMonth(d as date) as integer // full date of month in question d.day=1 d.month=d.month+1 d.day=d.day-1 return d.day end function ```[/quote]

Thanks Dave, it works very fine!

Just curious, is this for selecting a date? From my own point of view, a calendar pop-up is far more user friendly because it requires far fewer clicks. Apps may vary of course.

Hi Dave!, Calander popup? Its some kinda Xojo’s Plugin??

Ok I 've seen the thread: https://xojo.io/246330ef8be5
FromAxel Schneider

it’s really simple. I write the function that returns the number of days in a month, taking into account that every four years we have a leap year

``````function getmonthdays(year as integer, month as integer)
return integer

if year mod 4 <> 0 then

select case month
case 1,3,5,7,8,10,12
return 31
case 4,6,9,11
return 30
case 2
// leap calculation
if year mod 4 <> 0 then
return 28
else
return 29
end if
end select
``````

use this when change value both of year and month.
excuse for my english … I’m Italian.

except you code is “wrong”

[quote]In the Gregorian calendar three criteria must be taken into account to identify leap years:
The year can be evenly divided by 4;
If the year can be evenly divided by 100, it is NOT a leap year, unless;
The year is also evenly divisible by 400. Then it is a leap year.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.
[/quote]

Sure it will be a while before the error shows up… but the point is you don’t know what time frames a user may wish to analyze