Archived date functions

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

If you have rules that were created in server before November 2018 (server 4.1.5), then this is for you. If you are using cloud, this does not apply and instead of reading this, you can go and enjoy a cup of tea and a chocolate digestive.

Date functions and attributes are in the date reference section.

Warning

While the following syntax continues to work, it's highly recommended to use the newer dates syntax. Not only is it simpler to use, but it's more powerful and has a lot of bugs fixed in it.

Automation for Jira allows you to manipulate and format dates inside fields that support Smart Values, created, updated, duedate, resolutiondate, as well as the Date Picker custom fields, e.g. {{issue.MyDateFieldName}} or {{issue.customfield_12356}}.

Solution

You can specify the format of the date in 2 ways:

Specifying format

1 2 3 4 5 6 7 8 9 // To format a date field value {{#issue.resolutiondate}}longDateTime{{/}}{{#issue.MyDateFieldName}}longDateTime{{/}} // When no other fields are specified, you can include the format {{#now}}longDateTime{{/}} // When you specify timezone or a function to manipulate the date you need // to explicitly label the format and include the value in double quotes {{#now}}format="longDateTime",zone=Australia/Sydney{{/}}

There are a number of built-in formats or you can specify your own:

Format

Thursday, November 1, 1979 6:23:12 AM EST

Notes

Default (none specified)

Nov 1, 1979 6:23:12 AM

If no format is specified it defaults to mediumDateTime. This may not work if used as the input for some fields

toMillis

310303392034

This is how many milliseconds have passed since

Epoch

toSeconds

310303392

This is how many seconds have passed since

Epoch

toMinutes

5171723

This is how many minutes have passed since

Epoch

toHours

86195

This is how many hours have passed since

Epoch

toDays

3591

This is how many days have passed since

Epoch

Time zone

By default dates are displayed for the time zone as "UTC". This is the timezone of the Jira servers for OnDemand/Cloud and the default timezone used when allocating scheduled triggers.To specify another time zone you need to add a parameter:

1 2 //Prints the time in Sydney when the issue was created. {{#issue.created}}zone=Australia/Sydney{{/}}

Time zones are available in the Joda documentation.

Specify a user's timezone:

1 2 // Prints the time in the reporters time zone. {{#issue.created}}zone={{reporter.timeZone}}{{/}}

Language (locale)

By default, dates are in English. To specify another locale, specify the parameter:

1 2 // Prints the time in Sydney when the issue was created. {{#issue.created}}locale=ru_RU{{/}}

Available locales are available in the Java documentation.

Manipulating dates

Manipulate dates by setting particular parts of the date or add/subtracting values from it:

1 2 3 4 5 6 // Adds 7 days to the current time {{#now}}func=plusDays(7){{/now}} // You can chain functions. // Sets the day to the first of November {{#issue.created}}func=withDayOfMonth(1).withMonthOfYear(11){{/}}

Calculating business days

There are two sets of functions built in to work with business days - you can either plus/minus business days from the current date or find the closest business day to the current date.

1 2 3 4 5 6 7 8 9 10 11 12 // The next business day {{#now}}func=toBusinessDay(){{/}} // The next business day after 3 days {{#now}}func=plusDays(3).toBusinessDay(){{/}} // The previous business day {{#now}}func=toBusinessDayBackwards(){{/}} // Adds 6 business days to today {{#now}}func=plusBusinessDays(6){{/}} // The number of business days between when the issue was created and today {{#now}}func=businessDaysBetween({{issue.created}}), format="toDays"{{/}}

Calculating the difference between two dates

Use the "toSecond" format and the "minusSeconds" function to subtract one date from the other. Then use one of the formats that displays how many seconds, minutes, hours or days. There's also a shortcut method called daysBetween with simpler syntax.

1 2 3 4 5 // The number of hours since an issue was created {{#now}}func=minusSeconds({{#issue.created}}toSeconds{{/}}), format="toHours"{{/}} // The number of days between two dates {{#now}}func=daysBetween({{issue.created}}), format="toDays"{{/}}

Examples

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // May 1st this year {{#now}}func=withDayOfMonth(1).withMonthOfYear(5){{/}} // May 1st next year {{#now}}func=withDayOfMonth(1).withMonthOfYear(5).plusYears(1){{/}} // Last day of May {{#now}}func=withDayOfMonth(1).withMonthOfYear(6).minusDays(1){{/}} // First business day in May {{#now}}func=withDayOfMonth(1).withMonthOfYear(5).toBusinessDay(){{/}} // Last business day in May {{#now}}func=withDayOfMonth(1).withMonthOfYear(6).minusDays(1) .toBusinessDayBackwards(){{/}}

Updated on May 31, 2024

Still need help?

The Atlassian Community is here for you.