I needed to calculate a DateTime value for midnight in the local time zone, for comparison against other date fields in my policy. It’s painfully difficult to do, but just barely possible. Here’s my solution:
DateTimeNow() -> $now_utc Mid(DateTimeFormat($now_utc, "zz"), 1, 2) -> $timezone_offset ConvertToNumber(DateTimeFormat($now_utc, "HH")) -> $utc_hours DateTimeFromString(DateTimeFormat($now_utc, "dd/MM/yyyy"), "en-AU") -> $midnight_utc Subtract(24, ConvertToNumber($timezone_offset)) -> $rollover_hour IIF(LessThan($utc_hours, $rollover_hour), "0.00:00:00.0", "1.00:00:00.0") -> $timezone_day_fix Concatenate("-0.", $timezone_offset, ":00:00.0") -> $timezone_hour_fix DateTimeAdd(DateTimeAdd($midnight_utc, $timezone_hour_fix), $timezone_day_fix) -> $midnight_local
Please note that this only works for positive integer timezones (such as Australia/East) but at least it handles daylight savings correctly. For non-integer timezones, the $rollover_hour calculation would need to be extended, and for negative timezones something else would probably need to be done but I haven’t thought it through properly.
To be honest it would be a lot easier and more efficient to just write a custom activity!