Calculate number of days between a date field and the end of the year

Francesco Borgosano January 13, 2023

Hi,

 

I am trying to use Automation and Smart Values to automatically calculate the number of days between a date and the end of the year of the same date.

For example, if the date field value is 23/Jun/2024. I would like to know how many days are between that and 31/Dec/2024.

1 answer

1 accepted

4 votes
Answer accepted
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 13, 2023

Hello @Francesco Borgosano 

What have you tried?

You can get the difference between two dates using the diff function.

{{[date1].diff([date2]).[unit]}}

Reference this document:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time

If you need to construct the year-end date based on the Year specified in the date field use the format function on the date field to get the year. Example:

{{issue.created.format("yyyy")}}

Substitute your date field for "created".

Combine this with the day and month to get the year-end date, and use that to set a variable.

Screen Shot 2023-01-13 at 2.48.50 PM.png

 

That variable is a string so when you use it in the date diff function you need to convert it to a date.

{{now().diff(yearEnd.toDate).Days}}

 

Francesco Borgosano January 24, 2023

Hi @Trudy Claspill,

 

thanks for your reply. Your solution worked!

 

And I found particularly insightful and elegant your solution with the concept of creating a local variable. It gave me other ideas for further automation.  

Suggest an answer

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

Atlassian Community Events