Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert date from automation response to date in Assets

Svante Gustafsson Björkegren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2025

Hey community,

I have an automation that gets all my automations via REST. In the response from the REST API call the date is formatted like this:
"created": 1727255448.771000000

My automation is creating Asset objects for each automation and I would like to have the attribute "Rule created" in my object type as a DateTime attribute.

I have tried to convert the value provided in the rest response to a format that goes into an Assets DateTime attribute but so far no luck.

Any tips or tricks how I can format my smart value in my automation to be accepted as a DateTime attribute in Assets?

Cheers,
// Svante

1 answer

3 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2025

Hi @Svante Gustafsson Björkegren 

The value is the number of seconds since the start of Unix time: the start of day on 1 January 1970.

To convert that for use as a date / time, the number could be multiplied by 1000 to convert to milliseconds and added to 1 Jan 1970.  For example:

  • action: create variable
    • name: varStartOfTime
    • smart value: {{now.withYear(1970).withDayOfYear(1).toDateTimeAtStartOfDay}}
  • action: create variable
    • name: varMyMillis
    • smart value: {{#=}}ROUND(1727255448.771000000 * 1000, 0){{/}}
  • get the value for some action...
    • {{varStartOfTime.toDate.plusMillis(varMyMillis.asNumber)}}

 

When I tested your amount, I got: 2024-09-25T09:10:48.7+0000

 

Kind regards,
Bill

Svante Gustafsson Björkegren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 31, 2025

Hey Bill,

Thnx for your solution, that worked perfect! I have a followup question on these DateTime values.

When I have converted the Unix time value from the REST response I would like to compare that DateTime with the DateTime stored in my Assets object. I have tried a number of different approaches but I can't get it right. Maybe you can identify what  I am doing wrong here. I have attached two screenshots, one with the actions I have come up with and one from the audit log.

I think it is tricky to get the formats right.

Looking forward to hear back from you.

Cheers,
// Svante

compare-dates-log.pngcompare-dates.png

Like Stefan Salzl likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 31, 2025

Hi @Svante Gustafsson Björkegren 

I am glad to learn that helped!

Regarding the date / time comparisons, you are formatting the values with asLongDateTime and that converts them to text...preventing the function isAfter() from working: it expects a date or date / time type.

Please try removing the formatting to leave the values as date / time types for the comparison.

Like Stefan Salzl likes this
Svante Gustafsson Björkegren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2025

Hey @Bill Sheboy 

I have removed the formattings as you suggested. Unfortunately, this didn't do the trick.

I have created a test automation for this where I convert a Unix timestamp to a DateTime, as you described. And then I lookup my Asset object and get the DateTime attribute.

When I try to compare these I only get empty strings as a result. Looking at the log it seems that they are of different formats. I am not sure if this is just a textual issue or if it is something else that makes them incompatible.

Do you have any idea why these two Dates cannot be compared?

Cheers,
// Svante

compare-dates-log2.pngcompare-dates2.png

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2025

It appears the asset value is a text representation of the date / time, and that needs to be converted with toDate prior to the comparison.  Please try that first, and...

 

If that does not help, let's also try mitigating another possible problem: timing.  My understanding is some asset data is looked up just-in-time, and so latency can cause problems with smart value expressions, rule actions, conditions, etc.  The mitigation for that is to first store the value in a created variable to force full evaluation.  Then the variable is used in later expressions.

  • action: create variable
    • name: varRuleUpdated
    • smart value: {{lookupObjects.Rule updated}}
  • later use of the value as a date / time...
    • {{varRuleUpdated.toDate}}

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events