Skip to main content
Inspiring
April 18, 2008
Question

Set date to 1st Saturday ??

  • April 18, 2008
  • 1 reply
  • 288 views
I'm curious, how would I go about taking my date from a database, and
setting a new date to 2 months out from that date, but make sure that its on
the 1st Saturday of that month???



    This topic has been closed for replies.

    1 reply

    Inspiring
    April 18, 2008
    Steve Grosz wrote:
    > I'm curious, how would I go about taking my date from a database, and
    > setting a new date to 2 months out from that date, but make sure that its on
    > the 1st Saturday of that month???
    >
    >
    >


    Loop from the first day of the month until the dayOfWeek() function says
    the date is a Saturday. Wouldn't ever take more then seven iterations.

    Quick and dirty and completely untested.

    <cfset testDay = createDate(year, month+2, 1)>

    <cfloop condition="dayOfWeek(testDay) NEQ 1">
    <cfset testDay = dateAdd(testDay,'d',1)>
    <cfloop>

    <!--- IF all my above syntax is correct, I did NOT look up all the
    functions, testDay is the first Saturday. --->

    <cfoutput>#dateFormat(testDay, "mm/dd/yyyy dddd")#</cfoutput>