How can I convert a correctly formated (yyyy-MM-dd) string into a Date so that Date and Time operations like minusDays(1).toBusinessDayBackwards behave as expected and return a result.
When smartYear = 2022 & smartMonth = 01 & smartDay = 19
smartParsedDate = {{smartYear.concat("-").concat(smartMonth).concat("-").concat(smartDay).toDate().as("yyyy-MM-dd")}}
Results in {{smartParsedDate}} equaling "2022-01-19"
as per https://community.atlassian.com/t5/Jira-questions/Parse-a-datestring-in-a-smartvalue/qaq-p/1879743
however {{smartParsedDate.minusDays(1)}} returns an empty string as does
{{smartParsedDate.toBusinessDayBackwards}}
Hi @Jason G
Please try converting the text string to a date value first, such as with:
{{smartParsedDate.toDate}}
Kind regards,
Bill
I ran into this because my expectation was that I only had to do this once, such as when defining a variable. For example, if I create a variable called {{endOfYear}} as follows:
{{now.format("yyyy").concat("-12-31").toDate}}and try to use it elsewhere, the result depends on how I'm using it. If I just want to print the variable, it works fine:
2023-12-31T00:00:00.0+0000However, if I want to use it in a calculation, it fails:
{{endOfYear}} is {{now.diff(endOfYear).days}} days before the end of the year This produces:
2023-12-31T00:00:00.0+0000 is days before the end of the year
In order to get it to produce the expected result, you have to add the ".toDate" function to the variable where it's being used as a date; the function is lost if you try to make it part of the variable. I was able to make the above smart values work by adding the function to the variable when used in the diff:
{{endOfYear}} is {{now.diff(endOfYear.toDate).days}} days before the end of the yearProduces the result:
2023-12-31T00:00:00.0+0000 is 29 days before the end of the year
I'm posting this here in case anyone else is confused by the answer above. While it's correct, this nuance made it difficult for me to accomplish exactly what the originally poster was trying to do, and the answer above did not provide enough information.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wish I had discovered Mike's clarification sooner. I struggled for several days with smart values I incorrectly thought were "saving" a text string as a Date object.
"In order to get it to produce the expected result, you have to add the ".toDate" function to the variable where it's being used as a date; the function is lost if you try to make it part of the variable."
After following Mike's suggestion, I was finally able to get the toDate modifier working with a smart value. Based on this my impression is smart values are actually text strings which can only be used as Date objects in place with one of the date modifiers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Roy Presley -- Welcome to the Atlassian Community!
For Jira Cloud, created variables have always stored their values as text: https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Create-variable
And so they must be converted when used as other types: date, number, list, etc. The method of using the "source" smart value expression directly to preserve the typing works in some cases...but not in others. For example, where the smart value is dynamically looked up, requiring it to be first stored in a variable and converted later.
For Jira Data Center, there appears to be undocumented behavior for created variables. That is, they are not always text values...even when the "source" expression was text! Thus the workaround is often two-fold:
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bill,
Thanks for the clarification and work-around for Data Center's undocumented behavior. I will definitely save this one for future use!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I am really struggling to do the same thing here
I successfully pull a date string in the format MMM d, yyyy, and store it in a variable, but when I try to save that into a date field, it is empty.
I also tried directly populating the field using
{issue.description.substringBetween("|*When does it need to be completed ?*|", "|").toDate}}
and
{issue.description.substringBetween("|*When does it need to be completed ?*|", "|").toText.toDate}}
to no avail.
I put debug statements so I know that the value is present in the variable:
Date: March 15, 2026
Could it be that I have spaces at the end and have to trim these?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First thing...
This is a very old thread; please consider creating a new question with the "Ask a question" button at the top of the page, perhaps including a link back to this thread. That ensures the focus is on your scenario and the maximum number of people see it. Otherwise, only people mentioned or following very old threads will see it.
Back to your question, when using the toDate() function it tries to parse a date / time value, but can need help for some formats. Perhaps try adding the exact format needed, such as:
{{someSmartValue.toDate("MMM d, yyyy")}}
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.