Archived date functions

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}}.

Formatting dates

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

Specifying format

// 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:

FormatThursday, November 1, 1979 6:23:12 AM ESTNotes
Default (none specified)Nov 1, 1979 6:23:12 AMIf no format is specified it defaults to mediumDateTime. This may not work if used as the input for some fields
toMillis310303392034This is how many milliseconds have passed since Epoch
toSeconds310303392This is how many seconds have passed since Epoch
toMinutes5171723This is how many minutes have passed since Epoch
toHours86195This is how many hours have passed since Epoch
toDays3591This 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:

// 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:

// 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:

// 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:

// 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.

// 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.

// 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

// 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(){{/}}
Last modified on Apr 21, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.