Search code examples
datetimeautomationpower-automate

Getting daylight savings time in Power Automate


I have a flow which runs daily at 1am, setting some parameters for local time 9am to 5pm.

However, when daylight savings time ends the time goes to 8am to 4pm.

I am currently manually editing the times come DST, but thought there might be a way to automate it part of the flow.

AUS DST starts on the first Sunday in October 2am and ends on the first Sunday in April 3pm.

What I am trying to do is create two variables: StartTimeUTC and EndTimeUTC with one of the 9am to 5pm UTC times:

Then I would update this variable if DST starts or ends to a new hardcoded +/- hour.

I thought a good way to do this is with a condition, and if the DST time is true then update those two variables with the new HH value, otherwise do nothing. But I'm finding it hard to know what parameters it should be.

My questions are:

  • What would I need to add into the conditional so it updates only on DST time parameters?
  • Is there a better way to detect DST?

My conditional at the moment (before I got stuck) was:

  • Two groups
  • AND conditional for the two groups
  • Three rows in each group
    • G1 Row 1: formatDate(utcNow(), 'dd') <= 07 // is it in the first week
    • G1 Row 2: formatDate(utcNow(), 'MM') == 04 // is it April
    • G1 Row 3: formatDate(utcNow(), 'ddd') == Sun // is it Sunday
    • G2 Row 1: formatDate(utcNow(), 'dd') <= 07 // is it in the first week
    • G2 Row 2: formatDate(utcNow(), 'MM') == 10 // is it October
    • G2 Row 3: formatDate(utcNow(), 'ddd') == Sun // is it Sunday

But this is wrong because it only would run on the first Sunday in April AND the first Sunday in October, so it would always be false (since the date will never be at two places at once).

If I update it so it is greater than "04" and less than "10" for the months, then it only runs on Sundays between April and October.

At best I can only get it to work if I set it to check if it is greater and "04" and less than "10" so it runs true everyday between April and October. However, if in April the first Sunday (when DST ends) is the 7th of the month, then I would have 6 days of incorrect time in the variable. The same occurs of October.


Solution

  • The other way you might be able to do this is to use the dateDifference expression and then evaluate the amount of hours that is resulting.

    If you're in Sydney, 11 hours would indicate that it's DST and 10 would indicate that it's not.

    This is a flow that shows the thinking ...

    Flow

    Variables

    Initialize UTC Now ... utcNow()

    Initialize Sydney Now ... convertFromUtc(variables('UTC Now'), 'AUS Eastern Standard Time')

    Hours Difference ... int(first(split(dateDifference(variables('UTC Now'), variables('Sydney Now')), ':')))

    From there, you can set a variable (e.g. Is DST) to be true if the value equals 11.

    Results

    Is DST (you can see the date is in December)

    Initialize UTC Now Expression = addDays(utcNow(), -150)

    Is UTC

    Is NOT DST (you can see the date is is May)

    Initialize UTC Now Expression = utcNow()

    Is Not DST