Your code is doing what you tell it to Gina :)

<!----
><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>)
---->

Okay what is going on here, you have 4/01/01 as your date up top.

This is the first time you modify the date.. You are calling the
date add and adding two days to the current date. Two days is
4/03/01. That is as it should be. Then adding another day later would
push your date to 4/04/01.

A really simple way is to start out on the first day of the month
check to see if it is a weekend day, if it is increment the day
until you hit a non weekend day... first business day of the month.

Pseudo Code.

<cfset date = FirstDayOfMonth(Now())>
<cfif DayOfWeek(date) EQ 1 OR DayOfWeek EQ 7>
        <cfif DayOfWeek(date) EQ 1>
                <cfset date = DateAdd("d", 1, date)>
        <cfelse>
                <cfset date = DateAdd("d", 2, date)>
        </cfif>
</cfif>

This accomplishes what you want.. The nice thing about dates is
they remain fairly consistent so you can hardcode stuff and it
does not really change. You can get that code a bit more effecient..
but it works, and is simple.

If you are looking for the first Monday-Fri business week of the month
that is still relatively simple, using the same idea.


Jeremy Allen
elliptIQ Inc.


>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, January 02, 2001 11:37 AM
>To: CF-Talk
>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