Forum Discussion
Changing DateTime Value from UTC to AEDT
- 1 year ago
Your analysis is incorrect.
lt is not a function. Rather it transforms each datetime in your date time column from UTC datetimes to your local timezone time, be it standard time or daylight savings.
You did not provide a usable data sample, so the Source line is there only to create something. I inferred from your question that you had a column of datetimes.
My local timezone is EST (US-East coast).
Please note that the dates are showing as MDY (US style), not DMY.
Our change date from EDT to EST is on the first Sunday in November at 2AM which happens to be Nov 3 2024.
Perhaps it would be more clear if I showed it to you as an additional column
let Source = Table.FromColumns( {List.DateTimes(#datetime(2024,11,1,12,0,0), 24*7,#duration(0,1,0,0))}, type table[DateTimeUTC=datetime]), #"to Local Time" = Table.AddColumn(Source, "DateTimeLocal", each DateTime.From( DateTimeZone.ToLocal( DateTime.AddZone([DateTimeUTC],0))),type datetime) in #"to Local Time"will produce:
Note the change from EDT to EST at 2 AM on Nov 3 in the 2nd column.
A similar result should occur in Australia.
In the example code, I used the Source step to create a column of datetimes. In your code, you should insert the #"to Local Time" step at some point in your code after your datetime column has been created. You can either the version that transforms the column itself, or the one that adds an additional column.
It is only that #"to Local Time" step that is relevant to your question.
The Source step serves only to create a data sample, since you did not provide one.
In the #"to Local Time" step, you may need to change the Source reference and the column name(s) to match whatever you have.
Since you are converting to your local time zone, rather than your function, you can use the DateTimeZone.ToLocal function
let
Source = Table.FromColumns(
{List.DateTimes(#datetime(2024,11,1,12,0,0), 24*7,#duration(0,1,0,0))}, type table[DateTime=datetime]),
#"to Local Time" = Table.TransformColumns(Source,
{"DateTime", each
DateTime.From(
DateTimeZone.ToLocal(
DateTime.AddZone(_,0))),type datetime})
in
#"to Local Time"
There seem to be numerous problems with your query, but I did not look into it in detail, so could be wrong about a few things.
- The first Sunday of a month is NOT the first Sunday of the week that includes the first Day of the month.
- If Oct 1 happens to be on a Monday (or later), the first day of that week would be in September.
- Your switch to DST occurs when LOCAL datetime is between certain values; you appear to be checking the UTC datetime in your query.
I have no experience with SalesForce
Hi There,
I have attempted to use this code and the function produces a list of dates from 01/11/2024 to the 08/11/2024. Would you be able to ellaborate on implementation of the function?