Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Got a recipe for converting a unix timestamp to a utc date

(1) ShareShare
ReportReport
Posted on by 6

I have a json response that contains a date in unix timestamp format, anyone know how to convert it?

I tried converttoutc but it throws errors and I cant save the expression.

If that function doesnt work, anyone have a flow recipe to do this ?  Is it possible ?

  • HEATFreight Profile Picture
    1,020 on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    @cotton_gin1 I feel like I've landed on this comment of yours more than once, so thanks and thanks again!

  • juresti Profile Picture
    319 on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    @cotton_gin1  it did not work for me when dividing by 1000.

     

    It only added 18 days.

     

    08.PNG

  • juresti Profile Picture
    319 on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    @ericonline 

    I don't believe the formula addseconds is the issue.

     

    You have to figure out how to access the "time" field.

    First you need to test until you access "features", it could be item()?['features'] or it could be using an index item()[0]

     

    I always have to test for nested json since I forget when to use index and when to use property name.

     

    Once you access "features" then you figure out how to access "time" field.

  • Community Power Platform Member Profile Picture
    on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    Hi @PanooneHDA ,

    You will need to specify the timestamp field within your Flow.

    In your example: `addseconds('1970-1-1', Div(items('Apply_to_each')?['properties']?['timestamp'],1000),'yyyy-MM-dd hh:mm:ss')` expression, the `items('Apply_to_each)` refers to the "For Each" loop, `['properties']?['timestamp']` refers to the specific field to convert. 

    You'll need to "dig" into your own data structure to convert the timestamp.

  • PanooneHDA Profile Picture
    4 on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    @cotton_gin1 , can you please describe your complete working flow?

     

    When I test my flow, the Compose action is showing the Output is the same as the Input! Are any parts of the expression meant to use dynamic variables?

     

    Using:

    addseconds('1970-1-1', Div(items('Apply_to_each')?['properties']?['timestamp'],1000),'yyyy-MM-dd hh:mm:ss')

  • Community Power Platform Member Profile Picture
    on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    Hi @cotton_gin1 ,

     

    Do you have a recipe for converting FROM a UTC timestamp TO Unix time?

     

    Example

    I need to query an API using HTTP Action. The query requires a Unix timestamp format. I'm thinking of using Flow Get Current Time action, then wrapping it using a Compose Action. Think this will work?

     

    Need to convert:

    FROM: 2019-07-18T09:00:00-08:00 (or 2019-07-18T09:00:00Z)

    TO: 1563440400

     

    **EDIT** Found the answer here! https://powerusers.microsoft.com/t5/Flow-Ideas/Convert-Tima-Date-format-to-UNIX-Timestamp/idi-p/145710#M8964

  • Community Power Platform Member Profile Picture
    on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    @cotton_gin1 , thank you. Worked like a charm!

  • cotton_gin1 Profile Picture
    21 on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    @ericonline 

    That time field listed in your JSON is different than the one I was using. 

     

    Change your formula to divide by 1000.

    `addseconds('1970-1-1', Div(triggerBody()?['data']?['item']?['last_occurrence_timestamp'],1000),'yyyy-MM-dd hh:mm:ss')`

     

    That should work.

  • Community Power Platform Member Profile Picture
    on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    Hi @cotton_gin1 .

    Hm. I cannot seem to get this working using the recipe you provided (edited for my use case of course). 

    Can you identify what I'm missing?

    Trigger: Button

    Action1: HTTP Request
    Action2: Parse JSON

    • Here is where I get the Unix timestamp in a `time` parameter
    • Example output:
      • {
         "type": "FeatureCollection",
         "metadata": {
         "generated": 1557358894000,
         "url": "https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2019-05-07T00%3a00%3a00.0000000&endtime=5%2f8%2f2019&latitude=39.0422528&longitude=-95.6719104&maxradiuskm=1000&orderby=magnitude-asc",
         "title": "USGS Earthquakes",
         "status": 200,
         "api": "1.8.1",
         "count": 1
         },
         "features": [
         {
         "type": "Feature",
         "properties": {
         "mag": 2.9,
         "place": "16km N of Snyder, Texas",
         "time": 1557260837307,
         "updated": 1557331308692,
         "tz": -360,
         "url": "https://earthquake.usgs.gov/earthquakes/eventpage/us70003i1i",
         "detail": "https://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us70003i1i&format=geojson",
         "felt": 1,
         "cdi": 2.7,
         "mmi": null,
         "alert": null,
         "status": "reviewed",
         "tsunami": 0,
         "sig": 130,
         "net": "us",
         "code": "70003i1i",
         "ids": ",us70003i1i,",
         "sources": ",us,",
         "types": ",dyfi,geoserve,origin,phase-data,",
         "nst": null,
         "dmin": 0.028,
         "rms": 0.48,
         "gap": 36,
         "magType": "mb_lg",
         "type": "earthquake",
         "title": "M 2.9 - 16km N of Snyder, Texas"
         },
         "geometry": {
         "type": "Point",
         "coordinates": [
         -100.9142,
         32.8648,
         1.96
         ]
         },
         "id": "us70003i1i"
         }
         ]
        }

    Action3: Apply to Each

    • Using the Parse JSON output
    • Action4: Compose
      • I've tried the following 3 combinations to convert the Unix timestamp to no avail:
      • **Your Recipe:** `addseconds('1970-1-1', Div(triggerBody()?['data']?['item']?['last_occurrence_timestamp'],1),'yyyy-MM-dd hh:mm:ss')`
        
        **Test 1:** `addseconds('1970-1-1', items('Apply_to_each')?['properties']?['time'],'yyyy-MM-dd hh:mm:ss')`
        **RESULTS:** `InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '1' and column '2590': 'Value to add was out of range.
        Parameter name: value'.`
        
        **Test 2:** `addseconds('1970-1-1', Div(items('Apply_to_each')?['properties']?['time'],1),'yyyy-MM-dd hh:mm:ss')`
        **RESULTS:** `InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '1' and column '2590': 'Value to add was out of range.
        Parameter name: value'.`
        
        **Test 3:** `addseconds('1970-1-1', item()?['properties']?['time'],'yyyy-MM-dd hh:mm:ss')`
        **RESULTS:** `InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '1' and column '2590': 'Value to add was out of range.
        Parameter name: value'.`
    • I've also tried Compose, Set Variable, and Initialize Variable Actions before the Apply to Each action. No Go.

    Any ideas? 
    Thank you!

  • Community Power Platform Member Profile Picture
    on at
    Re: Got a recipe for converting a unix timestamp to a utc date

    Perfect, thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1