Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

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? 

 


  • Anonymous's avatar
    Anonymous
    7 years ago

    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

2 Replies

  • v-yuta-msft's avatar
    v-yuta-msft
    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's avatar
      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