Hi,

actually you can put the calculation in a formula, this way you don't need the 
multiple cfelseif's.... should be faster.

<cfset myDate = "12/20/2000">

<!--- subtract the value of Monday from DayOfWeek(givenDate) --->
<cfset diff = DayOfWeek(myDate) - 2>
<!--- calculate Date of Monday --->
<cfset monday = DateAdd("d", iif(diff LT 0, -6, "diff * -1"), myDate)>

Regards,

Chris


------Original Message------
From: "Larry Juncker" <[EMAIL PROTECTED]>
To: CF-Talk <[EMAIL PROTECTED]>
Sent: December 20, 2000 2:51:52 PM GMT
Subject: RE: How can I find the date of the Monday of the week containing a given date?


Try this Brent:

the code below will give you the date for Monday based on the date you enter

<cfset date = "12/18/2000">

<CFSET diff = 7 - dayofweek(date)>

<CFIF diff is 1>
        <CFSET diff = -4><!-- Today is Fri -->
<cfelseif diff is 2>
        <CFSET diff = -3><!-- Today is Thu -->
<cfelseif diff is 3>
        <CFSET diff = -2><!-- Today is Wed -->
<cfelseif diff is 4>
        <CFSET diff = -1><!-- Today is Tue -->
<cfelseif diff is 5>
        <cfset diff = 0><!-- Today is Mon -->
<cfelseif diff is 6>
        <cfset diff = +1><!-- Today is Sun -->
<cfelse>
        <cfset diff = +2><!-- Today is Sat -->
</CFIF>
<CFSET monday = dateadd("d", diff, date)>

<CFOUTPUT>
<!--- Sunday = 1 and Saturday = 7 --->
Mondays date is: #DateFormat(monday, "mmm dd, yyyy")#<BR>
</cfoutput>


Larry Juncker
Senior Cold Fusion Developer
Heartland Communications Group, Inc.


-----Original Message-----
From: Brent Goldman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 19, 2000 8:29 PM
To: CF-Talk
Subject: How can I find the date of the monday of the week containing a
given date?


Hello,

I am currently writing an online scheduling application with ColdFusion.  At
one part of the program, I output the next four weeks in case the user wants
to quickly jump ahead in time.  Rather than outputting weeks starting from
the current day, such as from a Tuesday like today, I want the weeks
starting from a Monday.  So today's week would be Dec 18 (Mon) - Dec 24
(Sun), not Dec 19 (Tue) - Dec 25 (Mon).

I've looked at all of the ColdFusion date functions, but I can't figure out
how to use them to retrieve the date of the Monday of the week containing a
given date.  Does anyone know how to do this?  Someone please help.

Thanks,
Brent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

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

Reply via email to