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

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

Reply
lukasjar
Resolver I
Resolver I

DirectQuery SQL Query UTC to Swedish time

Hello.

I have a database that has Timestamps written in UTC. Is it possible to write a SQL query so that it always converts these to Swedish time (also winter/summer time. Adding +"01:00:00" will not work as this does not take account for summer/wintertime).

 

I also have a query that just gives me the StartOfHour from the Timestamp above. Is it possible to write this with the same rules as above.

 

format(TimeTrue, 'HH') StartTimeHour

 

 

Thank you for any assistance on this!

1 ACCEPTED SOLUTION
lukasjar
Resolver I
Resolver I

https://stackoverflow.com/questions/8038744/convert-datetime-column-from-utc-to-local-time-in-select... 

Found this now when searching the web. Following code works for system time.

 

TimeTrue is my column name.

 

 

 

SELECT TOP 10
TimeTrue,
CONVERT(datetime, 
SWITCHOFFSET(CONVERT(datetimeoffset, 
TimeTrue), 
DATENAME(TzOffset, SYSDATETIMEOFFSET()))) 
AS ColumnInLocalTime

FROM PerformanceOpc (NOLOCK)
WHERE convert(varchar,TimeTrue,23)>='2021-02-22'

 

 

timetrue.JPG

View solution in original post

3 REPLIES 3
lukasjar
Resolver I
Resolver I

https://stackoverflow.com/questions/8038744/convert-datetime-column-from-utc-to-local-time-in-select... 

Found this now when searching the web. Following code works for system time.

 

TimeTrue is my column name.

 

 

 

SELECT TOP 10
TimeTrue,
CONVERT(datetime, 
SWITCHOFFSET(CONVERT(datetimeoffset, 
TimeTrue), 
DATENAME(TzOffset, SYSDATETIMEOFFSET()))) 
AS ColumnInLocalTime

FROM PerformanceOpc (NOLOCK)
WHERE convert(varchar,TimeTrue,23)>='2021-02-22'

 

 

timetrue.JPG

v-kelly-msft
Community Support
Community Support

Hi  @lukasjar ,

 

Using below M codes to realize it:

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTimeZone.SwitchZone(DateTime.AddZone([Column1],0),1))

And you will see:

v-kelly-msft_0-1615790076823.png

For the sample .pbix file,pls see attached.

 

Best Regards,
Kelly

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

Sorry Kelly but I can't add custom columns in direct query. I need to load the data in swedish time in the SQL query.

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