Working with dates

You can manipulate and format created, updated, duedate, resolutiondate dates (as well as the Date Picker custom field, e.g. {{issue.MyDateFieldName}} or {{issue.customfield_12356}}) inside fields that support Smart Values. Date functions and attributes are in the date reference section.

Old Syntax

For rules created prior to November 2018, refer to the old syntax documentation.

Formatting dates

You specify the format of a date at the end of the smart value:

// using inbuilt formats
{{issue.resolutiondate.asLongDateTime}}
{{issue.MyDateFieldName.longDateTime}}
{{issue.created.jqlDateTime}}
{{issue.created.mediumTime}}

// Or, you can specify the format
{{issue.dueDate.format("dd/MM/yyyy")}}
{{issue.created.as("dd MMM")}}

See our reference guide for a complete list of available date formats.

Locale (location based date format)

You can specify the locale to print the dates in (default is "US" locale).

// Prints the issue's created date in French
{{issue.created.withLocale("fr").asLongDateTime}}

// Prints the issue's created date in French Canadian
{{issue.created.locale("fr_CA").longDateTime}}

// Prints the issue's created date in the locale of the reporter
{{issue.created.locale(issue.reporter.locale).longDateTime}}

For a list of locales, please refer to Java documentation

Time zone

In Cloud dates are displayed in the "UTC" time zone.
In Server dates are displayed in Jira's default timezone.

To specify another time zone:

// Converts the issue's created time to the new timezone, 
// e.g. 10am UTC converts to 8pm AEST
{{issue.created.convertToTimeZone("Australia/Sydney")}}

// Converts the issue's created time to the new timezone and keeps the same
// times/dates. E.g. 10am UTC changes to 10am AEST
{{issue.created.setTimeZone("Australia/Sydney")}}

For a list of timezones, please refer to Java documentation.

Specify a user's timezone:

// Prints the issue's created time in the reporters timezone.
{{issue.created.convertToTimeZone(issue.reporter.timeZone)}}

Manipulating dates

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

// Add 7 days to the current time
{{now.plusDays(7)}}
 
// You can chain functions
// Set the created date to November 1st
{{issue.created.withDayOfMonth(1).withMonth(11)}}

Attributes of a date

Retrieve individual attributes of a day, e.g. the month

// Get today's day of the month
{{now.dayOfMonth}}
 
// Get the day of the week the issue was created
{{issue.created.dayOfWeekName}}

// Get the day name of the week in French
{{issue.created.locale("fr").dayOfWeekName}}

Calculating business days

Plus/minus business days from the current date or find the closest business day to the current date. Business days are considered Monday through Friday.

// The next business day
{{now.toBusinessDay()}}

// The next business day after 3 days
{{now.plusDays(3).toBusinessDay()}}

// The previous business day
{{now.toBusinessDayBackwards()}}

// Adds 6 business days to today
{{now.plusBusinessDays(6)}}

// The first business day of the month
{{now.firstBusinessDayOfMonth}}

// The last business day of the month
{{now.lastBusinessDayOfMonth}}

// The number of business days beeween when the issue was created and today
{{now.diff(issue.created).businessDays}}

Calculating the difference between two dates

The "diff" method to calculate the difference between two dates by passing in another date and then specifying the unit to measure.

// Gets how many hours since an issue was created
{{now.diff(issue.created).hours}}

// Gets the number of days between two dates
{{now.diff(issue.created).days}}

// To show positive dates use the "abs" method
{{now.diff(issue.created).abs.days}}

Comparing two dates

You can compare two dates. These methods take another date as the parameter.

// Returns "true"
{{now.isAfter(issue.created)}}

TIP

Compare dates using the Compare condition.

Converting text to dates

When a date is text, e.g. in the changelog, dates are stored as text:

{{issue.summary.toDate}}

Convert the text to a date if it's in the right format. You can specify the format to convert from, by adding the param. The example below converts text, e.g. "2017 6 11", into a date object.

{{issue.summary.toDate("yyyy MM dd")}}

Once you've converted text to a Date object, you'll may need to transform it further, e.g. for a field changed (e.g. listening for a change in date)

{{fieldChange.fromString.toDate.plusDays(1).longDate}}

Referencing the current date/time

You can reference the current date and time using {{now}}

Examples

// 1st of May this year
{{now.startOfMonth.withMonth(5)}}

// 1st of May next year
{{now.startOfMonth.withMonth(5).plusYears(1)}}

// last day of May
{{now.withMonth(5).endOfMonth}}

// first business day in May
{{now.withMonth(5).firstBusinessDayOfMonth}}

// last business day in May
{{now.withMonth(5).lastBusinessDayOfMonth}}