cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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

Accepted Solutions
Anonymous
Not applicable

Re: DateTime.AddAzone conversion is giving me wrong dates

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
Community Support Team
Community Support Team

Re: DateTime.AddAzone conversion is giving me wrong dates

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

Re: DateTime.AddAzone conversion is giving me wrong dates

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

Helpful resources

Announcements
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)