Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of in a Days in a Month

Status
Not open for further replies.

Phil99

Programmer
Jul 12, 2002
32
GB
Hi,

Has anyone got a good solution for calculating the number of days in a month, which will work for all years.

I need to perform a calculation based on the number of minutes in a month but I don't know how to return the number of days in that month.

Thanks

Phil
 
if month((DateField}) in [1,3,5,7,8,10,12] then 31
else if Month({DateField}) in [4,6,9,11] then 30
else if remainder(Year({Datefield},4)= 0 then 29 else 28.

Leap years are the only years perfectly divisible by 4.

One flaw to this formula -- there actually is a February 30th once every 400 years or so, I think we are due for the next one in 2200, but I think this formula should work. Software Sales, Training and Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
Another means is to use:

date(year(dateadd('m',1,currentdate)-1),month(dateadd('m',1,currentdate)-1),1)-1

This returns the number of days for the current month, or you can place a field in lieu of the currentdate.

-k kai@informeddatadecisions.com
 
There will never be another Feb 30.
The rules for determining if there is a leap year are:

Every year divisible by 4 is a leap year.
But every year divisible by 100 is NOT a leap year
Unless the year is also divisible by 400, then it is still a leap year

I've incorperated the rules into dgillz's formula

if month({DateField}) in [1,3,5,7,8,10,12] then 31
else if Month({DateField}) in [4,6,9,11] then 30
else if remainder(Year({DateField}),400)= 0 then 29
else if remainder(Year({DateField}),100)= 0 then 28
else if remainder(Year({DateField}),4)= 0 then 29 else 28 Mike
If you're not part of the solution, you're part of the precipitate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top