View comments | RSS feed

FirstDayOfMonth

Description

Determines the ordinal (day number, in the year) of the first day of the month in which a given date falls.

Return value

A number corresponding to a day-number in a year.

Category

Date and time functions

Syntax

FirstDayOfMonth(date)

See also

Day, DayOfWeek, DayOfWeekAsString, DayOfYear, DaysInMonth, DaysInYear

Parameters

Parameter Description
date

Usage

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

Example

<h3>FirstDayOfMonth Example</h3>

<cfoutput>
The first day of #MonthAsString(Month(Now()))#, 
 #Year(Now())# was 
  a #DayOfWeekAsString(DayOfWeek(FirstDayOfMonth(Now())))#,
   day #FirstDayOfMonth(Now())# of the year.
</cfoutput>

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

Version 6

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

Comments


tctmcg said on Nov 26, 2002 at 5:41 PM :
With this code you have to add a 2 to get the correct date.
hlichtin said on Mar 13, 2003 at 10:12 AM :
The example is wrong. The following code does not work and should be removed:

a #DayOfWeekAsString(DayOfWeek(FirstDayOfMonth(Now())))#,
day

Otherwise I do not see a need to add any days.
cartman29 said on Oct 16, 2003 at 10:21 AM :
the value returned is not the one this explanation claims to be!
SEQ said on Nov 2, 2003 at 12:53 PM :
This code is off by one day. I found this to work. Of course, it will return an error if the first DayOfWeek value is 1.

<cfoutput>
The first day of #MonthAsString(Month(Now()))#
#Year(Now())# was
#DayOfWeekAsString(DayOfWeek(Now()-1))#.
</cfoutput>
conradw said on Jun 1, 2005 at 11:01 AM :
The correct code should be:

<cfoutput>
The first day of #MonthAsString(Month(Now()))#,
#Year(Now())# was
a #DayOfWeekAsString(DayOfWeek(FirstDayOfMonth(Now())-1))#,
day #FirstDayOfMonth(Now())# of the year.
</cfoutput>
No screen name said on Sep 26, 2006 at 4:18 PM :
The critical flaw with this example is explained by Ben:

The value that DayOfWeek() expects is a date time object, not an ordinal date. If you pass an ordinal value to it then you'll get odd values, or rather, the same value for every year for February 5th in particular. To do what you are trying to do you need to convert the ordinal date to a real date, use DateAdd() to add that many days to Jan 1st (that many days - 1, actually) and it should do what you want.

from:
http://www.houseoffusion.com/groups/CF-Talk/thread.cfm/threadid:9573#47508
halL said on Sep 27, 2006 at 6:58 AM :
The last commenter is correct.
The example will not work, and was replaced by the following example in the ColdFusion MX 6.1 documentation.

<cfoutput>
The first day of #MonthAsString(Month(Now()))#, #Year(Now())# was
day #FirstDayOfMonth(Now())# of the year.
</cfoutput>

Also, please note that this page is for ColdFusion 6.0, not 6.1 or 7.0.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt183.htm