Forum Discussion
Syntax error in custom function to covert UTC to Central Time
- 1 year ago
The error messages often point to something other than what they specifically indicate.
Examining the code window can give you some hints.
For example, there is no `mod` operator in PQ and you will see that it has a wavy red underline in the editor:
You need to use the `Number.Mod` function.
Also, if your computer itself is set to Central Time, there is a much simpler method to convert to local time (or to the local time of whatever a computer is set to (and it will take DST into account):
// Function to convert UTC to Local Time) (ConvertUTCtoLT as datetime) => let addTZ = DateTime.AddZone(ConvertUTCtoLT,0), toLocal = DateTimeZone.ToLocal(addTZ), localDateTime=DateTime.From(toLocal) in localDateTime
Yes, the Number.Mod() function cleared the error for me, thank you!
My computer is not in Central Time, and I'm actually having to convert the date time column to different time zones, because we have data for different locations all coming in UTC time zone. So I think I'm stuck with having to create a custom column for each timezone I need.
Thank you!
Do all your timezones have the same datetime for the DST shift?
- dhirata1 year agoFrequent Visitor
I am not sure I'm understanding your question correctly... but I think the answer is yes. I have a column in UTC time zone. And the table has records for locations that are in different time zones (Pacific, Central, Mountain, etc.) And all those locations shift to/from DST on the same datetime. Is that what you are asking?
- ronrsnfld1 year agoSuper User
If you happen to be in one of those time zones (or if you could set your computer to one of those time zones), you could first use the function I provided to get one of them, then simply add/subtract one or more hours to get the local times in the other zones.
I don't know if that would be simpler for you.
- dhirata1 year agoFrequent Visitor
Ah, I see. Yes, I think that would be simpler! Thank you so much.