Hello everyone and welcome to my blog. I am back with another blog on Power Apps and this blog is going to be short and sweet. In today’s blog I will discuss on how to convert Unix (epoch) time to DateTime and vice versa in Power Apps canvas apps.
First of all we need to understand what is Unix time. UNIX time or Epoch time is the number of seconds since 1st of January, 1970.
There are many systems which stores timestamp value in UNIX format. And if your Power Apps is integrating with any such systems, which need the date in Unix or Epoch format, this blog will show you how to do that.
So let’s get started. First we will convert DateTime to Epoch format. There is no Unix function in Power Apps. Infact quite unknown to many, the Text function can itself convert your DateTime into Unix (epoch) format.
Below is an illustration.
As you can see in the above screenshot, we are basically using the Text function to convert it into Unix time. The trick is to pass empty string the format (second parameter) of the Text function.
Below is the code if you want to copy.
Text(Date(2022, 10, 10), "")
Great! How about the reverse? Converting the UNIX time to regular date and time?
It’s very easy. You remember when I explained UNIX time at the starting of the blog. So basically you need to add the number milliseconds to1970-01-01. And below is the formula to achieve it.
I use the DateAdd function and add the UNIX second to the starting date (1970-01-01).
DateAdd(Date(1970,01,01), 1602268200000,Milliseconds)
Hope this helped. You will also like the below posts.
Debajit Dutta
Business Solutions MVP
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.