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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
spartanboy
Helper II
Helper II

Get datetime in CST in local and workspace

Hi,

 

I need to show report refresh datetime in CST zone on local machine as well as on workspace. Below M code to get UTC datetime and convert to CST.

 

Local machine is always shows in CST, but on publishing the repor to workspace get conveted to UTC

 

let
    // Get the current UTC datetime
    Source = DateTimeZone.UtcNow(),
    
    // Convert the UTC datetime to CST by subtracting 6 hours (CST is UTC-6)
    CSTDateTime = DateTimeZone.SwitchZone(Source, -6),
    
    // Convert the datetime to text with CST label
    CSTDateTimeText = DateTime.ToText(DateTime.From(CSTDateTime), "yyyy-MM-dd HH:mm:ss") & " CST",
    
    // Convert the result to a table
    #"Converted to Table" = #table(1, {{CSTDateTimeText}}),
    
    // Rename the column to "DateTime"
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table", {{"Column1", "DateTime"}})
in
    #"Renamed Columns"

 

2 ACCEPTED SOLUTIONS

Please try this code and adjust the number '6' below according to your Pwer bi service time zone

 

let
// Get the current UTC datetime
Source = DateTime.FixedLocalNow() - #duration(0,6,0,0),

#"Converted to Table" = #table(1, {{Source}}),
#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type datetime}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "DateTime Refresh"}})
in
#"Renamed Columns"

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

View solution in original post

You can also add this to your code as well Source = DateTimeZone.UtcNow() - #duration(0,6,0,0),

here is the result in service

aj1973_0-1721691506922.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

View solution in original post

4 REPLIES 4
aj1973
Community Champion
Community Champion

Hi @spartanboy 

Timezones of local machines and power BI service might be different. Try using 
CurrentDateTime = DateTime.LocalNow() and then subtract number of hours according to the time rendered by the service.

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

by doing the same i still have the same issue. can you please provide an example?

You can also add this to your code as well Source = DateTimeZone.UtcNow() - #duration(0,6,0,0),

here is the result in service

aj1973_0-1721691506922.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Please try this code and adjust the number '6' below according to your Pwer bi service time zone

 

let
// Get the current UTC datetime
Source = DateTime.FixedLocalNow() - #duration(0,6,0,0),

#"Converted to Table" = #table(1, {{Source}}),
#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type datetime}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "DateTime Refresh"}})
in
#"Renamed Columns"

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Helpful resources

Announcements
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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.