Gina,

You're making just one mistake in your code.  That's in using the function
FirstDayOfMonth().  This function returns the ordinal day in the year, a
number from 1 to 365 (or 366).  When you then use the function DayOfWeek()
on this number the results don't really have any meaning, since DayOfWeek()
is supposed to take a number from 1 to 7.

#DayOfWeekAsString(DayOfWeek(FirstDayOfMonth(firstdate)))#

All you really need is the function DayOfWeek(), which takes any date
(always use the first day in the month) and returns a number from one to
seven.

<cfif DayOfWeek(thedate) eq 7>
  <cfset FirstBusinessDay = DateAdd("d", 2, thedate)>
<cfelseif DayOfWeek(thedate) eq 1>
  <cfset FirstBusinessDay = DateAdd("d", 1, thedate)>
<cfelse>
  <cfset FirstBusinessDay = thedate>
</cfif>

Jim


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, January 02, 2001 9:37 AM
Subject: FirstDayOfMonth problems


> I am trying to create an option in my CF calendar that allows repeating
> events that relocate themselves to the first business day of the month.
For
> example, if the 1st falls on a Saturday, relocate that event to the 3rd,
or
> Monday, the first business day. I have a problem with FirstDayOfMonth,
> however - it keeps returning the wrong day (one day earlier than it
> should). Here is my example code, with April 1, 2001 hard coded in since
> April 1st falls on a Sunday:
>
> <cfset thedate="04/01/2001">
>
> <CFOUTPUT>
> <P>
> Date: #dateFormat(thedate, "mm/dd/yyyy")#.
> <BR>This date is a #DayofWeekAsString(DayOfWeek(thedate))#, day
>   #DayOfWeek(thedate)# in the week.
> <BR>This is day #Day(thedate)# in the month of
>   #MonthAsString(Month(thedate))#, which has
>     #DaysInMonth(thedate)# days.
> <BR>This date is in week #Week(thedate)# of #Year(thedate)# (day
>   #DayofYear(thedate)# of #DaysinYear(thedate)#).
> <BR><CFIF IsLeapYear(Year(thedate))>This date is in a leap year
>     <CFELSE>This date is not in a leap year</CFIF>
> <P>
> The first day of #DateFormat(thedate,"mmmm")#,
>   #DateFormat(thedate,"YYYY")# is
>     a #DayOfWeekAsString(DayOfWeek(FirstDayOfMonth(thedate)))#
*****NOTE***** (<B>this should return Sunday but returns Saturday</B>),
>       day #FirstDayOfMonth(thedate)# of the year.
>
> <P>
>
> The first day of the month is: #DayOfWeek(FirstDayOfMonth(thedate))#
*****NOTE***** (<B>This should return 1 but returns 7</B>)
>
> <cfif DayOfWeek(FirstDayOfMonth(thedate)) IS 7>
>
> <P>
> <cfset FirstBusinessDay = DateAdd("d",2,thedate)>
> first business day = #DateFormat(firstbusinessday,"dddd, mmmm dd, yyyy")#
*****NOTE***** (<B>This should return Monday, 04/02/2001 but returns
>  Tuesday, 04/03/2001</B>)
>
> <cfelseif DayOfWeek(FirstDayOfMonth(thedate)) IS 1>
> <P>
> <cfset FirstBusinessDay = DateAdd("d",1,thedate)>
> first business day = #dateformat(firstbusinessday,"dddd, mmmm dd, yyyy")#
> </CFIF>
>
> </CFOUTPUT>


~~~~~~~~~~~~~ Paid Sponsorship ~~~~~~~~~~~~~
Get Your Own Dedicated Win2K Server!      Instant Activation for $99/month w/Free 
Setup from SoloServer      PIII600 / 128 MB RAM / 20 GB HD / 24/7/365 Tech Support     
 Visit SoloServer, https://secure.irides.com/clientsetup.cfm.

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to