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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Solution Sage
Solution Sage

@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
Solution Sage
Solution Sage

@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
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors