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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DateTime.AddAzone conversion is giving me wrong dates

I have a date with Date Time Values. This DateTime is in IST time zone. I used DateTime.AddZone("Date Column Name", -6) to convert this to MST (Mountain Standard Time). But the resulting DateTime is not correct as you can see below.

 

Time is converted correctly but the Denver time for the given India time should be 1/3/2019 5:30 AM instead of 1/4/2019 5:30 AM. Why the date is 4th instead of 3rd? 

 


Capture.PNG

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you so much for replying. I finally got the result by doing the below.

 

  • Step 1: Add a custom column with the formula --> DateTimeZone.From (This is to bring the current time zone information to the existing DateTime column)
  • Step 2: Add another column using the above new column --> DateTimeZone.SwitchZone ([Created On],-6) -- This is to create a new column but switching it to MST
  • Step 3: Add new column using above new column -->DateTimeZone.RemoveZone -- This is to remove the zone info from the above column
  • Step 4: Change the above column's type to DateTime

View solution in original post

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

Hi kvijayrs173,

 

If you mean achieve the -6 hour switch datetime based on the local datetime, you can create a custom column using power query below:

 

 

 = DateTimeZone.SwitchZone(DateTimeZone.LocalNow(), -6, 0)

If you mean achieve the -6 hour switch datetime based on the india column, you may use power query below:

 

 = [India Time] - #duration(0, 6, 0, 0)

 

You can also refer to the attached sample pbix file.

 

Regards,

Jimmy Tao

 

Anonymous
Not applicable

Thank you so much for replying. I finally got the result by doing the below.

 

  • Step 1: Add a custom column with the formula --> DateTimeZone.From (This is to bring the current time zone information to the existing DateTime column)
  • Step 2: Add another column using the above new column --> DateTimeZone.SwitchZone ([Created On],-6) -- This is to create a new column but switching it to MST
  • Step 3: Add new column using above new column -->DateTimeZone.RemoveZone -- This is to remove the zone info from the above column
  • Step 4: Change the above column's type to DateTime

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors