← Al Davies, 250 High Street

How to get the first and last day of the month in Power Automate

Use startOfMonth(utcNow()) for the first day. For the last day, add one month to that date, then subtract one day. Power Automate has no built-in end-of-month function.

What is the expression for the first day of the month?

Add a Compose action and enter startOfMonth(utcNow()). The function returns midnight on the first day of the month that holds the date you give it.

To get a plain date, add a format string: startOfMonth(utcNow(), 'yyyy-MM-dd'). Without it, the result is a full timestamp.

What is the expression for the last day of the month?

Start from the first day, move forward one month, then step back one day: addDays(addToTime(startOfMonth(utcNow()), 1, 'Month'), -1, 'yyyy-MM-dd').

Because you step back from the first day of the next month, the result is right for 28, 29, 30 and 31 day months. It also handles leap years.

How do you get the previous or next month?

  1. First day of last month: startOfMonth(addToTime(utcNow(), -1, 'Month'), 'yyyy-MM-dd').
  2. Last day of last month: addDays(startOfMonth(utcNow()), -1, 'yyyy-MM-dd').
  3. First day of next month: startOfMonth(addToTime(utcNow(), 1, 'Month'), 'yyyy-MM-dd').
  4. Last day of next month: addDays(addToTime(startOfMonth(utcNow()), 2, 'Month'), -1, 'yyyy-MM-dd').

How do you get only the day number of the last day?

Use 'dd' as the format. The expression addDays(addToTime(startOfMonth(utcNow()), 1, 'Month'), -1, 'dd') returns 28, 29, 30 or 31.

The 'dd' result is text, so wrap it in int() before you compare it to dayOfMonth(utcNow()) in a Condition. If they match, today is the last day of the month. This works for a daily flow that must act only on month end.

Why is the date off by one day?

utcNow() returns UTC time. Late in the evening in a US time zone, UTC is already the next day, so the month can differ by one day at the boundary.

Convert first: convertTimeZone(utcNow(), 'UTC', 'Eastern Standard Time'). Use that value inside startOfMonth(). See the guide on formatDateTime and time zones for the zone names.

How do you filter SharePoint items from this month?

Put the first day in a variable and the first day of next month in a second variable. In Get items, use a filter such as Created ge 'first' and Created lt 'next'.

Using less than the next month start avoids missing items created late on the last day. If the filter returns nothing, check the column name and the date format. For filter errors, see Get items filter query not working.

FAQ

Does Power Automate have an endOfMonth function?

No. There is startOfMonth(), but no end-of-month function. Add one month to the start, then subtract one day.

Does the last-day expression handle leap years?

Yes. It steps back from the first day of the next month, so February gets 28 or 29 days on its own.

Can a flow run only on the last day of the month?

Run a daily Recurrence trigger. Add a Condition that checks whether dayOfMonth(utcNow()) equals int() of the last-day number.

Sources