Examples of using smart values with dates

Check out how we use smart values in our Jira automation template library.

You can use smart values to manipulate and format created, updated, duedate and resolutiondate dates.

These functions can also be used on the date picker custom field, for example, {{issue.MyDateFieldName}} or {{issue.customfield_12356}}, inside fields that support smart values.

View the smart values available to manipulate and format dates.

Formatting dates

Specify the format of a date at the end of the smart value, as shown below. View available date formats.

1 2 3 4 5 6 // using inbuilt formats {{issue.resolutiondate.asLongDateTime}} {{issue.MyDateFieldName.longDateTime}} {{issue.created.jqlDateTime}} {{issue.created.mediumTime}} {{issue.Sprint.endDate.jiraDate}} - format the Sprint field's end date into a format suitable to set another field
1 2 3 // Or, you can specify the format {{issue.dueDate.format("dd/MM/yyyy")}} {{issue.created.as("dd MMM")}}

Locale (location based date format)

Specify the locale to print the dates in (default is "US" locale).

1 2 // Prints the issue's created date in French {{issue.created.withLocale("fr").asLongDateTime}}
1 2 // Prints the issue's created date in French Canadian {{issue.created.locale("fr_CA").longDateTime}}
1 2 // Prints the issue's created date in the locale of the reporter {{issue.created.locale(issue.reporter.locale).longDateTime}}

For a list of locales, refer to the Java documentation.

Time zone

By default, dates are displayed in the "UTC" time zone. To specify another time zone:

1 2 3 // Converts the issue's created time to the new timezone, // e.g. 10am UTC converts to 8pm AEST {{issue.created.convertToTimeZone("Australia/Sydney")}}
1 2 3 // 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, refer to the Java documentation.

Specify a user's timezone

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

1 2 // Add 7 days to the current time {{now.plusDays(7)}}
1 2 3 // You can also 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.

1 2 // Get today's day of the month {{now.dayOfMonth}}
1 2 // Get the day of the week the issue was created {{issue.created.dayOfWeekName}}
1 2 // Get the day name of the week in French {{issue.created.locale("fr").dayOfWeekName}}

Calculating business days

Plus or minus business days from the current date, or find the closest business day to the current date. Business days are considered Monday through Friday, 9am to 6pm.

1 2 // The next business day {{now.toBusinessDay()}}
1 2 // The next business day after 3 days {{now.plusDays(3).toBusinessDay()}}
1 2 // The previous business day {{now.toBusinessDayBackwards()}}
1 2 // Adds 6 business days to today {{now.plusBusinessDays(6)}}
1 2 // The first business day of the month {{now.firstBusinessDayOfMonth}}
1 2 // The last business day of the month {{now.lastBusinessDayOfMonth}}
1 2 // The number of business days beeween when the issue was created and today {{now.diff(issue.created).businessDays}}

Calculating the difference between two dates

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

1 2 // Gets how many hours since an issue was created {{now.diff(issue.created).hours}}
1 2 // Gets the number of days between two dates {{now.diff(issue.created).days}}
1 2 // To show positive dates use the "abs" method {{now.diff(issue.<date field>).days.abs}}

Comparing two dates

Compares two specified dates. These methods take another date as the parameter.

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

Compare dates using the Advanced compare condition.

Converting text to dates

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

1 {{issue.summary.toDate}}

Converts the text to a date if it's in the correct format. You can specify the format to convert from, by adding the parameter.

The below example converts text, e.g. "2020 02 15", into a date object.

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

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

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

Referencing the current date/time

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

Example

1 2 // 1st of May this year {{now.startOfMonth.withMonth(5)}}
1 2 // 1st of May next year {{now.startOfMonth.withMonth(5).plusYears(1)}}
1 2 // last day of May {{now.withMonth(5).endOfMonth}}
1 2 // first business day in May {{now.withMonth(5).firstBusinessDayOfMonth}}
1 2 // last business day in May {{now.withMonth(5).lastBusinessDayOfMonth}}

Still need help?

The Atlassian Community is here for you.