JQL search for items in custom timerange

Hi - I need to search for issues created in the last month for a report dashboard, however the business rules of the company for reporting purposes is that their month ends on the last Friday of every normal calender month. I had been using

createdDate > startOfMonth(-1) and createdDate < endOfMonth(-1)

but it is naturally starting on the 1st and ending on either the 30th or 31st, as you would expect, so this is close, but not actually doing exactly what i need.

To give a specific example of what I need, in April of 2016, I want to filter for anything in the previous month. So based on the business rule that Friday is the last day,  I want the filtered range to end Friday 25th March, but the tricky part is the start of the range is actually 27 Feb.

I need the filter to be reusable, so obviously cant hard code and dates etc. Any ideas as to how I could search for my custom period? 

1 answer

I don't think you can do this without a custom JQL function. Normally I would be suggesting writing your own with ScriptRunner, but there is a small bug that prevents using relational operators with custom functions. I've fixed it, but won't be released for a couple of weeks. 

If you want to write your own see https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/jql-function-plugin-module, the important stuff for getting the last Friday of every month is in the getValues method. Code is at https://gist.github.com/jechlin/25557469af8b8013f62c6e4d3852be27.

So to get stuff resolved in the previous month you would use:

resolutiondate > endOfBusinessMonth(-2) and resolutionDate <= endOfBusinessMonth(-1)



Thanks very much Jamie, I'll save this in my script root and will wait for the SR update you mentioned to trial it...

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,682 views 18 21
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you