View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > DaysInMonth PreviousNext

DaysInMonth

Determines the number of days in a month.

The number of days in the month in Date.

Date and time functions

DaysInMonth("date")

Day, DayOfWeek, DayOfWeekAsString, DayOfYear, DaysInYear, FirstDayOfMonth

Parameter

Description

date

Date/time object, in the range 100 AD-9999 AD.

When passing a date/time object as a string, you must enclose it in quotation marks. Otherwise, it is interpreted as a numeric representation of a date/time object.

Note: You can pass the Now function or the CreateDate function as the date parameter of this function; for example: #DaysInMonth(CreateDate(2001, 3, 3))#

<h3>DaysInMonth Example</h3>
<cfif IsDefined("FORM.year")>
   More information about your date:
   <cfset yourDate = CreateDate(FORM.year, FORM.month, FORM.day)>
   <cfoutput>
   <p>Your date, #DateFormat(yourDate)#.
   <br>It is #DayofWeekAsString(DayOfWeek(yourDate))#, day 
#DayOfWeek(yourDate)# in the week. <br>This is day #Day(YourDate)# in the month of
#MonthAsString(Month(yourDate))#, which has #DaysInMonth(yourDate)# days. <br>We are in week #Week(yourDate)# of #Year(YourDate)#
(day #DayofYear(yourDate)# of #DaysinYear(yourDate)#). <br><cfif IsLeapYear(Year(yourDate))>This is a leap year <cfelse>This is not a leap year</cfif> </cfoutput> </cfif>

Contents > CFML Reference > ColdFusion Functions > DaysInMonth PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


Bryan_Hogan said on Feb 10, 2004 at 8:20 AM :
If you pass a month number into the this function, it will always return 31 instead of an error that daysInMonth() only accepts dates.
halL said on Feb 10, 2004 at 11:59 AM :
I believe that this is actually a "feature" not an issue. Because ColdFusion is typeless, it determines whether the month value CAN be a valid date in any representational format, including its internal date time object format (a number), and then treats is as such. If you do a createODBCDate on the month numbers you will see that to ColdFusion, the digits 1-31 correspond to 12/31/1899 - 1/11/1900.
Bryan_Hogan said on Feb 10, 2004 at 12:43 PM :
If it asks for a date it should throw an error when it is not a date. I don't think it is a feature, and I can't see why someone would write 3 so it will be interpreted as 1900-01-01T00:00:03.

If MM insists on leaving this in they should re-write the docs to clarify this.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functi65.htm