No it should work regardless of today's date... All date math
basically follows the same principals... A week is 7 days long, so you
know that you can adjust a date value by weeks either by using
dateadd("w",x,date) or by using dateadd("d",x*7,date) with x being the
number of days. In this case we're wanting to deal with "calendar
weeks", which begin and end on a specific day. The function
dayOfWeek(date) returns a number (1-7) indicating the current day. So
if I want the first day of the current week, all I have to do is ajust
the date so that dayOfWeek(date) would return 1... and I can do that
by subtracting 1 from the current day of the week and subtracting the
result from the current date.

(Although I did just see I typo'd the formula, so my post was still
incorrect.)

<!--- on monday this returns 1 --->
<cfset currentday = dayofweek(now())>

<!--- on monday this returns 0
-- which would be the day of week
if we used zero-index numbers to count them --->
<cfset currentday = currentday - 1>

<!--- on monday april 11/2005 this returns -- well, monday april
11/2005 --->
<cfset today = now()>

<!--- monday is the first day of the week, so on monday the date is
not adjusted --->
<cfset firstdayofweek = dateadd(d,-currentday,today)>

In the code this translates to:

monday: firstdayofweek = dateadd("d",-0,now()) = monday
tuesday: firstdayofweek = dateadd("d",-1,now()) = monday
wednesday: firstdayofweek = dateadd("d",-2,now()) = monday

You see where this is going... I just put it all on one line, although
the correct code is:

<cfset firstdayofthisweek = dateadd("d",1-dayofweek(now()),now())>

algebra
:: 1-dayofweek(now()) is the same as -(dayofweek(now())-1) ::

It's not as difficult as people think it is...

> Not quite sure I grasp that, Isaac...would that only work
> if it were run on the second day of the week?

> Rick

>> -----Original Message-----
>> From: S.Isaac Dealey [mailto:[EMAIL PROTECTED]
>> Sent: Monday, April 11, 2005 2:04 PM
>> To: CF-Talk
>> Subject: Re: Last Week...
>>
>>
>> > Could anyone tell me the most efficient way to get the
>> > start and end dates of the past full week?
>>
>> > Thanks!
>>
>>
>> <cfset firstdayofthisweek =
>> dateadd("d",dayofweek(now())-1,now())>
>>
>> From there you can add -7 days to get the first day of
>> last week or -1
>> day to get the last day of last week.


s. isaac dealey   954.522.6080
new epoch : isn't it time for a change?

add features without fixtures with
the onTap open source framework

http://macromedia.breezecentral.com/p49777853/
http://www.sys-con.com/author/?id=4806
http://www.fusiontap.com



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:202235
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to