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?
Because there is no datediff function, we need to use the ticks function.
Unix Epoch => ticks('1970-01-01Z00:00:00')
Subtract Unix timestamp from input datetime.
As Unix time is the amount of seconds, we need to divide the ticks (100-nanoseconds) result by 10.000.000
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)