Copy link to clipboard
Copied
I need to know the date of the last Monday
If today is Monday then I need todays date
If today is Tuesday then I need yesterdays date etc....
If today is Sunday then I need to know the date 6 days ago etc....
Copy link to clipboard
Copied
the day() function will tell you what day of now() is as an integer: 1=Sunday 7=Saturaday.
You know that Monday is 2. The difference between today's number and Monday's number (with a little mathmatical juggling to wrap Sunday to the previous week -- I would probably just convert -1 to 6 with a simple if statement after substracting 2 from the day() value.).
Subtracting (adding a negative value) of this difference with the dateAdd() function will give you the date of that previous Monday.
Copy link to clipboard
Copied
<cfset todayDayNumber = dayOfWeek(now())>
<!--- since Monday's day-of-week is 2 --->
<cfset lastMondayRelativeDayNumber = todayDayNumber - 2>
<!--- adjust if today is Sunday --->
<cfif todayDayNumber is 1>
<cfset lastMondayRelativeDayNumber = 6>
</cfif>
<cfset lastMonday = dateAdd("d",-lastMondayRelativeDayNumber,now())>