Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
gutovanzin
Frequent Visitor

Get current time in UNIX timestamp

Hello!

 

I created a blank Query that returns the current date and time in ISO format.

= DateTimeZone.SwitchZone(DateTimeZone.LocalNow(),-3,0)
Returns: 2021-01-13T16:03:28.8506372-03:00

 

Is it possible to get the same result however on UNIX Timestamp? Like:

1610519337000

 

Best, 
Luis

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Try this @gutovanzin 

 

 

 = Duration.TotalSeconds(DateTime.LocalNow() - #datetime(1970,1,1,0,0,0))

 

 

It simply gives you the total seconds from Jan 1, 1970 at midnight through now. Replace my DateTime.LocalNow() with your DateTimeZone.SwitchZone() function and it will work just fine.

 

edhans_0-1610568179212.png

You can round that with Number.Round if you don't need all of the decimals.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

If you are looking for a formula to the the current UTC Epoch Time, try this:

= Number.Round(Duration.TotalSeconds(DateTimeZone.UtcNow() - DateTimeZone.FromText("1970-01-01T00:00:00Z")))

 

If you need the value in millisecond UTC Epoch Time, use this:

 

= Number.Round(Duration.TotalSeconds(DateTimeZone.UtcNow() - DateTimeZone.FromText("1970-01-01T00:00:00Z")) * 1000)

 

 

edhans
Super User
Super User

@gutovanzin - I have written a more complete article on this at my blog site. It won't go live until 9am Pacific on Friday, Jan 15 though. But you can see it then. In the mean time, if you have any questions let me know. Otherwise if you could give thumbs up to any posts that have helped and mark one or more as the solution so this thread can be known to be solved it would be appreciated.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Super User
Super User

Try this @gutovanzin 

 

 

 = Duration.TotalSeconds(DateTime.LocalNow() - #datetime(1970,1,1,0,0,0))

 

 

It simply gives you the total seconds from Jan 1, 1970 at midnight through now. Replace my DateTime.LocalNow() with your DateTimeZone.SwitchZone() function and it will work just fine.

 

edhans_0-1610568179212.png

You can round that with Number.Round if you don't need all of the decimals.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Hello!
Thanks for the help, i'm trying to get my timezone, but got this error:

 

= Duration.TotalSeconds(DateTimeZone.SwitchZone(DateTime.LocalNow(),-3) - #datetime(1970,1,1,0,0,0))

 

Expression.Error: We cannot convert the value #datetime(2021, 1, 14, 8, 40, 13.0448086) to type DateTimeZone.
Details:
Value=14/01/2021 08:40:13
Type=[Type]

 

Any suggestion?
Thanks!

You cannot use DateTime.LocalNow in a timezone function. It doesn't have any timezone data. You need to use DateTimeZone.FixedLocalNow or DateTimeZone.LocalNow.

 

However, I am not certian you should use any of those anyway. Unix Epoch time is always UTC +0, and when you load this report in the service, DateTime.LocalNow() as I used above also calculate as UTC +0, so it will be apples to apples. Once you get it into Unix Epoch time, then add (3600 * n) seconds to your final answer, where N is your timezone offset.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
blopez11
Super User
Super User

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors