I’m trying to create a “dynamic” event that always represents “this week”. It should have a $StartDate
of last Sunday, and an $EndDate
of this Saturday. For example, today is 2020-12-09, so the $StartDate
should be 2020-12-06 and the $EndDate
should be 2020-12-12.
I can get last Sundays’ date with: $StartDate=date(today-today.weekday);
but I’m stumped with getting Saturday’s date.
I thought $EndDate=date(today-today.weekday+"7 days")
would work and give “Dec 12, 2020”, but it gives me “Nov 2, 2020”. I think it might be a bug. Here’s (almost) everything I tried.
Broken
The following all give “Dec 6, 2020” (last Sunday), as if the interval was ignored
$EndDate=date(today-today.weekday+interval("7 days"));
$EndDate=date(today-today.weekday) +interval("7 days");
$EndDate=today-today.weekday+interval("7 days");
These also don’t work right:
-
$EndDate=date(today+interval("7 days"));
is Dec 9 instead of 16. -
$EndDate=today+interval("7 days");
is Dec 9 instead of 16. -
$EndDate=today-today.weekday+"1 week";
give May 6, 2020 -
$EndDate=(today-today.weekday)+"1 week";
also gives May 6 (thankfully!)
-
$EndDate=today-today.weekday+"1 day";
gives Nov 8, 2020
Works
But these work fine:
-
$EndDate=date(today+"7 days");
works fine and gives Dec 16, 2020 -
$EndDate=today+"7 days";
works fine and gives Dec 16, 2020
This is using version 8.8.0 (b479) on macOS 10.15.7.
I’ve read the following articles to lead me to something that mostly worked, but they still didn’t provide an answer:
- Getting the week of the year from a date - #15 by geowyn
- How to do date/time arithmetic? - #3 by mwra
- Simple date arithmetic - #5 by eastgate
- aTbRef on
interval
and on Interval Data Type - And the official docs on
interval