This Week vs Next Week

Unsure if this has already been asked or if this is something that exists, but I'm trying to automate a simple section of text. Basically I want to eliminate a dropdown that says "this" week or "next" week.

{formmenu:next;this} week.

I'm thinking of creating a string of if/else statements that has the user enter the future date. Based on that date the if/else statements will check which day of the week was selected and if the current date also falls on or after the previous Sunday. (The date itself will be used multiple times in the same snippet so there is a time-save there if anyone is curious)

Is there an easier way to do this?

Thank you in advance!

Hi @Andrew_Blackburne,

Great question! Here's how you would do it.

Date 1:
{formdate: YYYY-MM-DD; name=date1}
Date 2:
{formdate: YYYY-MM-DD; name=date2}

{difference={time: W; at={=date2}} - {time: W; at={=date1}}}

{if: difference == 0}
This week.
{elseif: difference == 1}
Next week.
{elseif: difference == -1}
Last week.
{elseif: abs(difference) > 1 AND {time: X; at={=date1}} < {time: X; at={=date2}}}
In {=abs(difference)} weeks time.
{elseif: abs(difference) > 1 AND {time: X; at={=date1}} > {time: X; at={=date2}}}
{=abs(difference)} weeks ago.
{endif}

In this case I used two date pickers just to illustrate the workflow, but you could substitute the first one with a regular time command that gives you the current date, then use that.

Let me know if you have any other questions. Also, would love to see the end result. Please post it here if you're comfortable sharing it :blush:

2 Likes

Question?

I was playing around with this and noticed that it does not understand the years 100% of the time. See attached image which should reflect 1 week, not 51 weeks. And I have tried but failed to get it work!
Any ideas?

dates

Yeah, you probably want to change difference to be:

{difference={time: YYYY; at={=date2}}*52+{time: W; at={=date2}} - {time: YYYY; at={=date1}}*52-{time: W; at={=date1}}}

Perfect! I missed a bit of the breakdown when reworking the original, which corrects what I was looking to update. Thank you.