<cfset obj = structNew()>
<!--- lets setup a date here and call it td (today) --->
<cfset obj.td = dateAdd('d',-4,now())>
<!--- get the ordinal day of the week for that date --->
<cfset obj.ToDay = DayOfWeek(obj.td)>
<!--- if the ordinal day of that week is a 1 or a Sunday, lets get last weeks beginning --->
<cfif obj.ToDay EQ 1>
<cfset obj.lastsunday = DATEADD('d',-7,obj.td)>
<cfset obj.thissunday = obj.td>
<!--- if the ordinal day of that week is a Monday, lets get the previous Sunday and the current from yesterday --->
<cfelseif obj.ToDay EQ 2>
<cfset obj.lastsunday = DATEADD('d',-8,obj.td)>
<cfset obj.thissunday = DATEADD('d',-1,obj.td)>
<cfelse>
<!--- else tues(3) - sat(6), lets do some math and figure it out --->
<cfset obj.tmp = obj.ToDay - 1>
<cfset obj.lastsunday = DATEADD('d',-(obj.tmp+7),obj.td)>
<cfset obj.thissunday = DATEADD('d',-obj.tmp,obj.td)>
</cfif>
<cfdump var="#obj#">
Gert's:
<cfset dSunday = int(now()/7)*7+1>
or
<cfset dSunday = now() - now() % 7 + 1>
Jason's version
<cfscript>
dtThisWeek = fix( obj.td );
objThisWeek = structNew();
objThisWeek.Start = dateFormat(dtThisWeek - dayOfWeek( dtThisWeek ) + 1);
objThisWeek.End = dateFormat( objThisWeek.Start + 6 );
</cfscript>
My Version - struct |
LASTSUNDAY |
{ts '2023-11-19 18:28:27'}
|
TD |
{ts '2023-12-01 18:28:27'}
|
THISSUNDAY |
{ts '2023-11-26 18:28:27'}
|
TMP |
5
|
TODAY |
6
|
or
Gert's version:
1: 45256
2: 45256.7697569
And Jason's version here:
Fix value: " 45261 "
Jason's object - struct |
END |
02-Dec-23
|
START |
26-Nov-23
|