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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
hughcjohnson
New Member

DateTimeZone.UtcNow()

Is DateTimeZone.UtcNow() functioning correctly?

 

When I tested it today (9th April 2024) at 10:47 BST (which is one hour ahead of UTC), it returns "09/04/2024, 10:47:34.439". Surely it should have returned "09/04/2024, 09:47:34.439".

 

Am I missing something?

1 ACCEPTED SOLUTION
johnbasha33
Super User
Super User

@hughcjohnson  

DateTimeZone.UtcNow() is a function in Power Query that returns the current date and time in Coordinated Universal Time (UTC). It should indeed return the current time in UTC regardless of the time zone of the machine running the query.

In your case, since you tested it on April 9th, 2024, at 10:47 BST (British Summer Time), which is one hour ahead of UTC, you are correct that the UTC time should have been 09:47:34.439, not 10:47:34.439.

It's possible that there might have been some issue with the environment or the Power Query implementation you're using. I'd recommend double-checking the system time settings and ensuring that there are no issues with the Power Query environment.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

View solution in original post

4 REPLIES 4
hughcjohnson
New Member

@johnbasha33 thanks for the suggestion. The surprising point is that DateTimeZone.UtcNow() is returning the value that I want (BST when it is BST in the UK and GMT when it is not), so I have removed my adjustment code and I get the answer that I want. I am merely wondering why DateTimeZone.UtcNow() is returning BST and not UTC.

johnbasha33
Super User
Super User

@hughcjohnson  

DateTimeZone.UtcNow() is a function in Power Query that returns the current date and time in Coordinated Universal Time (UTC). It should indeed return the current time in UTC regardless of the time zone of the machine running the query.

In your case, since you tested it on April 9th, 2024, at 10:47 BST (British Summer Time), which is one hour ahead of UTC, you are correct that the UTC time should have been 09:47:34.439, not 10:47:34.439.

It's possible that there might have been some issue with the environment or the Power Query implementation you're using. I'd recommend double-checking the system time settings and ensuring that there are no issues with the Power Query environment.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

@johnbasha33  the Power Query environment is a Dataflow in the Power BI Service. Before the UK move from GMT to BST at the end of last month DateTimeZone.UtcNow() was correctly returning the UTC time. Now the same query, running in the Power BI Service as part of a Dataflow is returning the time in BST. As it happens, this is very convenient for me as I had added logic for the next few years to adjust the UTC value to BST when appropriate. I have removed this logic now and I am getting the answer that I want (BST now, and GMT before) simply using DateTimeZone.UtcNow(). Are there custom settings in the Power BI Service that I should be aware of? It is a regular Power BI Pro account.

you might wana reduce 1 hour in your code to be in sync with BST. @hughcjohnson 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.