# Power Query; Convert Time Stamp to Date Time

Power Query has number of Date and Time functions that convert values to date and time. However I haven’t found a function that converts a timestamp value. Fortunately it is easy to calculate a date time from a timestamp value. In this post I’ll explain an easy way of converting timestamp to date time. To Learn more about Power Query read Power BI online book; from Rookie to Rock Star.

# What is Timestamp

Timestamp is a whole number value, which is number of seconds from date 1970-01-01 00:00:00. For example; timestamp 100 means 1970-01-01 00:01:40, or timestamp 86400 means 1970-01-02 00:00:00. So the calculation is easy; We have to add timestamp as seconds to the date/time 1970-01-01 00:00:00.

# Power Query Convert Timestamp to Date Time

Once we know what is definition of timestamp, and how to calculate date/time from it; easily we can use #duration(0,0,0,<timestamp value>) to show duration in seconds, and add it to the #datetime(1970,1,1,0,0,0) which is date time 1970-01-01 00:00:00.

So as a result, here is the code to convert timestamp to date time;

`DateTimedValue=#datetime(1970,1,1,0,0,0)+#duration(0,0,0,1415697165)`

above query will respond  11/11/2014 9:12:45 AM.

Please note that you have to replace the 1415697165 number with the field name containing timestamp values, or with your static timestamp value in the query.

Save

Save

Trainer, Consultant, Mentor
Reza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc in Computer engineering; he has more than 20 years’ experience in data analysis, BI, databases, programming, and development mostly on Microsoft technologies. He is a Microsoft Data Platform MVP for 12 continuous years (from 2011 till now) for his dedication in Microsoft BI. Reza is an active blogger and co-founder of RADACAD. Reza is also co-founder and co-organizer of Difinity conference in New Zealand, Power BI Summit, and Data Insight Summit.
Reza is author of more than 14 books on Microsoft Business Intelligence, most of these books are published under Power BI category. Among these are books such as Power BI DAX Simplified, Pro Power BI Architecture, Power BI from Rookie to Rock Star, Power Query books series, Row-Level Security in Power BI and etc.
He is an International Speaker in Microsoft Ignite, Microsoft Business Applications Summit, Data Insight Summit, PASS Summit, SQL Saturday and SQL user groups. And He is a Microsoft Certified Trainer.
Reza’s passion is to help you find the best data solution, he is Data enthusiast.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog: https://radacad.com/blog.

## 3 thoughts on “Power Query; Convert Time Stamp to Date Time”

• Moe says:

Hi Reza,
I’m using “Direct Query mode” and it doesn’t work for me.