Forums

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

Calculating the number of days since year start

Martin Hazell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 9, 2024

I am trying to calculate the number of days since the start of the year in an automation, and am struggling to get it to calculate correctly.

I have tried various ways of doing it, and now have two variables:

YearStart: {{now.startOfMonth.withMonth(1)}}

NumberofDays: {{now.diff({{YearStart.toDate}}).days}}

When running it I get an error: Failed to get value for now().diff({{YearStart.toDate: {{now().diff({{YearStart.toDate}}).days}}

I am at a loss as to what to try next.

2 answers

1 accepted

2 votes
Answer accepted
Evgenii
Community Champion
January 9, 2024

Hi, @Martin Hazell 

Welcome to Atlassian Community

Try this formula. It works

{{YearStart.toDate.diff(now).days}}

I used variable YearStart like yours, but if you want, you can use such smart value, it will take 1 month, 1-st day, 1 minute.

{{now.startOfMonth.withMonth(1).withHour(0).withMinute(0)}}
Action details:
Log action
Log
YearStart: 2024-01-01T21:29:07.7+0000
Log action
Log
NumberofDays: 8

Screenshot_17.png

Martin Hazell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 10, 2024

Fantastic - couldn't get my head round why at first. 

This has worked.

Many thanks

Martin

0 votes
Florian Bonniec
Community Champion
January 9, 2024

Hi @Martin Hazell 

 

I do not have Cloud instance to test it but this should work.

{{now.diff(now.startOfMonth.withMonth(1).withHour(0)).days}}

Regards

Evgenii
Community Champion
January 9, 2024

Checked it. This will give -8 in result

Suggest an answer

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

Atlassian Community Events