none
How to Convert DateTime to UNIX Time RRS feed

  • Question

  • I'm new to Power Query. Inside Power BI I need to generate a Document DB query to get all events happened within the past month. It is easy to get a DateTime representing a month ago: Date.AddMonths(DateTime.FixedLocalNow(), -1) for example.

    The result is of DateTime type, but I need to query against UNIX time (an integer). How to convert my DateTime variable to UNIX time?

       
    Friday, April 15, 2016 7:02 PM

Answers

  • Thanks a lot, Curt! You pointed me to the right direction. In your answer I had to replace comma with minus sign since TotalSeconds take only duration as a single parameter:

    Duration.TotalSeconds(Date.AddMonths(DateTime.FixedLocalNow(), -1) - #datetime(1970, 1, 1, 0, 0, 0))


    Friday, April 15, 2016 8:13 PM

All replies

  • It should be something like (datetime) => Duration.TotalSeconds(datetime, #datetime(1970, 1, 1, 0, 0, 0))
    Friday, April 15, 2016 7:16 PM
  • Thanks a lot, Curt! You pointed me to the right direction. In your answer I had to replace comma with minus sign since TotalSeconds take only duration as a single parameter:

    Duration.TotalSeconds(Date.AddMonths(DateTime.FixedLocalNow(), -1) - #datetime(1970, 1, 1, 0, 0, 0))


    Friday, April 15, 2016 8:13 PM