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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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