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+0000
However, 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 year
Produces 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.