How can I compare dates between an issue and a sprint to run an automation?
Asked by Bruno Leite Cervantes:

Hi there,  

I'm trying to create an automation to add a label in a card added after a sprint starts. In my organization, we have to label the new cards added after the sprint started as "added points". To avoid doing this manually - most of the times people forget to add the label - I created an automation to compare the issue created date with the sprint start date. I tried to use smart values to save each of dates in the same format, and I used {{issue.created.format("dd/MM/yyyy")}} and {{issue.Sprint.startDate.format("dd/MM/yyyy")}} to assign the format dates to the two smart values created. When I run the automation, I'm getting an error, so I added a last step to write the two dates (issue.created and issue.Sprint.startDate) in the comment section. When it ran again I got something like this:  

- issue.created = 2024/07/09 12:30:22.22 pm"   
- issue.Sprint.startDate = Wed, Jun 20, 2024 1:30:05 pm"

I guess the format is not working due to the different format the dates are set in the issue and the sprint. Is there a way to compare these dates? Thank you. I appreciate your help.

Regards,  
Bruno


Answers:
author: Laurie Sciutti
body: hello [@Bruno Leite Cervantes](/t5/user/viewprofilepage/user-id/5540054) and welcome to the Community! If you happen to use ScriptRunner, you might be able to use the **addedAfterSprintStart** Enhanced Search JQL function: <https://docs.adaptavist.com/sr4jc/latest/features/scriptrunner-enhanced-search/jql-functions#addedaftersprintstart>


author: Mikael Sandberg
body: Hi [@Bruno Leite Cervantes](/t5/user/viewprofilepage/user-id/5540054)

Welcome to Atlassian Community!

Have you tried using one if the other formats to compare the dates instead of using the format? Like jiraDate or jqlDate?

comments: author: Bruno Leite Cervantes
body: Hi [@Mikael Sandberg](/t5/user/viewprofilepage/user-id/853579) ! Yup, I did and still doesn't work. Here's the screenshot with the issue created date and the sprint start date. Even if I use jiraDate, the "diff" function isn't working when I try to compare the dates.  

![image (6).png](https://community.atlassian.com/t5/image/serverpage/image-id/334615i8F9F7584F080955B/image-size/large?v=v2&px=999 "image (6).png")


author: Mikael Sandberg
body: One thing that you could try is convert the sprint start date, which looks like it is a text converted date, to a date format like this:

{{issue.Sprint.startDate.toDate}}


author: Bruno Leite Cervantes
body: I made a workaround to manipulate the dates. I'm running some tests, but apparently is working. Thank you for your tips!

Regards,

Bruno


author: Bruno Leite Cervantes
body: What I did was:   

1. Check if **{{issue.created.diff(now).days}}** **is greater than {****{issue.Sprint.startDate.diff(now).days}}.** If it is, I'm labelling the card as "pull-ahead".

2. Check if **{{issue.created.diff(now).days}} is less than {{issue.Sprint.startDate.diff(now).days}}**, I'm labelling as "new point".


author: Trudy Claspill
body: Hello [@Bruno Leite Cervantes](/t5/user/viewprofilepage/user-id/5540054)

Welcome to the Atlassian community.

When asking for help with an Automation Rule, it is vital that you share with us screen images showing the complete rule and the details of each step. Obscure confidential information. It is also helpful if you share with us the details in the Audit Log generated when the rule ran.

comments: author: Bruno Leite Cervantes
body: Thanks for the advice [@Trudy Claspill](/t5/user/viewprofilepage/user-id/5309476) . Here are the screenshots. The last screenshot is the date written in the comment field after the automation ran.  

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/334603i3DFC678067BDBC80/image-size/large?v=v2&px=999 "image.png")![image (1).png](https://community.atlassian.com/t5/image/serverpage/image-id/334604iBABF26ECC5A70840/image-size/large?v=v2&px=999 "image (1).png")![image (2).png](https://community.atlassian.com/t5/image/serverpage/image-id/334605i19651EF8AD4D29DF/image-size/large?v=v2&px=999 "image (2).png")![image (3).png](https://community.atlassian.com/t5/image/serverpage/image-id/334608i225E9DCBB746DD37/image-size/large?v=v2&px=999 "image (3).png")![image (4).png](https://community.atlassian.com/t5/image/serverpage/image-id/334609iD290E92F84246C3B/image-size/large?v=v2&px=999 "image (4).png")![image (5).png](https://community.atlassian.com/t5/image/serverpage/image-id/334610iD52AEE8FC80624F4/image-size/large?v=v2&px=999 "image (5).png")  
![image (6).png](https://community.atlassian.com/t5/image/serverpage/image-id/334611i9B0CE3EBA676C9EE/image-size/large?v=v2&px=999 "image (6).png")  


author: Trudy Claspill
body: Why are you creating variables and then using the variables in your comparison? You can simply use the smart values you used to create the variables.

{{issue.created.diff(issue.Sprint.startDate).days}}

When you create Variables the values are stored as text. The "diff" function can be used only with smart values that are Date or Date/Time types.

I think if you use the Log action to print out the smart value you were using with the Variables you will find you are not getting the answer you expect. But if you simply use the original issue smart values then you will get closer.

The diff function can return a positive or negative number. I recall that depends on how the date fields are referenced, but I never remember which way to go. So you might want to use a Log action to print out the above value also to check if it is returning a positive or negative number as you expect.


Tags: cloud

issue-create

jira-cloud

smart-value