I am trying to get the last weekend date from the ...
# cfml-general
g
I am trying to get the last weekend date from the function https://cffiddle.org/app/file?filepath=92500f6a-634c-43c8-a097-d10c276a7fda/cff6364[…]d72-b8ee-195f8ae16e92/f263fced-ed8e-478d-a930-9360123b32f1.cfm currently like if todays date is 22nd march and the weekendayday is 'sunday', it could be any like friday or saturday, i am trying that it should return the weekend date to me as Sunday the 17th and if its friday or saturday, it will go to that previous to get either 15th or 16th, what am currently doing wrong in it, it is returning me 16th instead
j
You can simplyfy this by replacing the IF logic with the following
// Calculate the start and end dates of the previous week
var endDate = DateAdd("d", -dayOfWeek + 1, currentDate);
var startDate = DateAdd("d", -6, endDate);
g
but it assumes the weekday starts on Monday
my weekday can start on sunday or friday too
in that what is the approach
j
Sorry, I misunderstood the requirement.
If I understand correctly the following should give you what you need, if not please clarify what you are expecting.
// Calculate the start and end dates of the previous week
var endDate = DateAdd("d", ((sWeekdayIndex eq 1) ? 0 : -7) - DayOfWeek + sWeekdayIndex  , currentDate);
var startDate = DateAdd("d", -6, endDate);
g
not exactly, so here i will explain again the red is the today date the green is the section means the weekendday is Sunday, so the week will start from Monday to the Sunday the Green line shows that 11 to 17th march are the previous weekend, like this the case for the friday and saturday will work, but in their case, the start of the week can be sunday or saturday and the weekendday will be either friday or saturday
j
The latest code I posted returns the 17th if you run for Sunday, 16th if you run for Saturday & 15th if you run for Friday. If that is not what you want then what dates do you expect?