Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a smart value date function that can get a particular day of the current week?

Anthony Roldan August 11, 2023

There are comparable functions like withMinute(num), withHour(num), described here, but unfortunately it does not work with withdayOfWeek(num), attributes listed here. I'm trying to get this because I want to create a cut-off date for a task, so I want to  compare the time now and check if it's before or after Thursday. I.e., {{now.isBefore(now.withDayOfWeek(4))}} {{now.withDayOfWeek(4)}} {{/}}

2 answers

2 accepted

1 vote
Answer accepted
Trudy Claspill
Community Champion
August 11, 2023

Hello @Anthony Roldan 

Try this instead.

Use an Advanced compare

Screen Shot 2023-08-11 at 10.22.20 AM.png

now.dayOfWeek will return the current day of the week (i.e. 5 for Friday) and you can compare that to 4 (for Thursday) to determine if the current day of week is before or after Thursday).

Anthony Roldan August 11, 2023

Thanks for the workaround!

0 votes
Answer accepted
Anthony Roldan August 11, 2023

So I haven't expanded on my use-case for this. I have two due dates, Tuesdays and Thursdays, with a desired cutoff of the day before at 5pm. So anything submitted after 5pm on Mondays will be due Thursday, and anything after 5pm on Wednesdays will be due on Tuesday. The problem is that you have to make multiple comparisons to pull this off, so I separated the function into 3 variables, {{tuesdayCutOff}}, {{thursdayCutOff}}, and {{dateTwo}}.

image.png

Here they are defined...

{{tuesdayCutOff}}

{{#if(now.isBefore(now.withNextDayOfWeek("TUE").withHour(21).withMinute(0).withSecond(0).minusDays(1)))}}
{{now.withNextDayOfWeek("TUE")}} {{/}}
{{#if(not(now.isBefore(now.withNextDayOfWeek("TUE").withHour(21).withMinute(0).withSecond(0).minusDays(1))))}}
{{now.withNextDayOfWeek("THU")}} {{/}}

 {{thursdayCutOff}}

{{#if(now.isBefore(now.withNextDayOfWeek("THU").withHour(21).withMinute(0).withSecond(0).minusDays(1)))}}
{{now.withNextDayOfWeek("THU")}} {{/}}
{{#if(now.isBefore(not(now.withNextDayOfWeek("THU").withHour(21).withMinute(0).withSecond(0).minusDays(1))))}}
{{now.withNextDayOfWeek("TUE")}} {{/}}

{{dateTwo}}

{{#if(now.withNextDayOfWeek("TUE").isBefore(now.withNextDayOfWeek("THU")))}}
{{tuesdayCutOff}} {{/}}
{{#if(now.withNextDayOfWeek("THU").isBefore(now.withNextDayOfWeek("TUE")))}}
{{thursdayCutOff}} {{/}} 

Let's start with the main event, {{dateTwo}}. We do a simple check to see if the following Tuesday will be before the following Thursday. If so, use {{tuesdayCutOff}}. If not, then use {{thursdayCutOff}}.

 

{{tuesdayCutOff}} and {{thursdayCutOff}} use the same logic, so for brevity's sake, I'll use the former as an example. The only thing that changes between them are the days.

 

The variable checks to see if {{now}} is before the following Tuesday at 5pm minus 1 day (so Monday 5pm). If so, use {{now.withNextDayOfWeek("TUE")}}. If not, use {{now.withNextDayOfWeek("THU")}}. The variable as a whole serves to check if we made the cutoff time or not, so if we didn't make it before 5pm, then the due date is set for the following Thursday.

I hope this helps someone in the future!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events