Calculating dates of beginning and end to the week

Hi, and welcome to the forum, and thanks for taking the trouble to describe what has hasn’t worked. For me, both your start and End date methods fail, But, I have a solution:

$StartDate=date("today -"+today.weekday+" days");
$EndDate = $StartDate + "6 days";

I should explain the logic for the change. The .weekday value of date("today") is 3`, as I write this. So in literal values the $StartDate is:

$StartDate=date("today - 3 days");

Note how the expression is a string. But, we want the ‘3’ to be a variable, so we break the string inside date() into two parts and concatenate (i.e. join together) into the middle today.weekday so it is evaluated. In truth I didn’t think this was possible, I assume that because the today part is already inside a day() operator so is evaluated into date-type data and the weekday is then returned into the statement to return the needed ‘3’ back into the overall string.

The enddate is easier, the end of the week is the sixth day after the start date. If the latter is correct then the latter will be, even across a month boundary.

Do ask if that doesn’t make sense!

Perhaps, I need to add to this article to include examples that use attribute values as in the post you cited, or inline use of an operation within date() as above. I’m also tempted to move the description of date calculations out of that article and into a new article in the section on Actions, Rules & Action code. Would that have been more helpful when you were looking for guidance on this??

1 Like