Handle Unix timestamp in Power Automate

For my Epic Shit with Power Plattform and Tesla Series, I had to convert Unix epoch timestamp to datetime and I found out that this is a little bit more effort than a normal convert. If your service also works with Unix timestamps and you want to convert them. Then this post is for you.

What is Unix timestamp?

Unix time measures time by the number of seconds that have elapsed since
1 January 1970 00:00:00 UTC (beginn of Unix epoch)

2022-12-06 17:00:00 is in Unix Time 1670342400 seconds

How to get Unix timestamp from DateTime?

  1. Because there is no datediff function, we need to use the ticks function.
    Unix Epoch => ticks('1970-01-01Z00:00:00')

  2. Subtract Unix timestamp from input datetime.

  3. As Unix time is the amount of seconds, we need to divide the ticks (100-nanoseconds) result by 10.000.000
    div(sub(ticks(2022-12-06Z17:00:00),ticks('1970-01-01Z00:00:00')), 10000000)

How to get DateTime from Unix timestamp?

That is easier and you can use the function addSeconds. Remember Unix timestamp is the amount of seconds from the beginning of Unix epoch.

addSeconds('1970-01-01Z00:00:00', Unix timestamp)
addSeconds('1970-01-01Z00:00:00', 1670342400)

Photo by Lukay Blazek on Unsplash