web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Error with DayofWeek f...
Power Automate
Answered

Error with DayofWeek for Sunday in Power Automate

(0) ShareShare
ReportReport
Posted on by 8

Hi all,

 

With my flow, I have it set up that whenever there's a change in a SharePoint item on a list, that it will send an email.  One of the aspects of the email is to notate a time and actual day (not date).  This flow is working perfectly as expected except for when it is done on Sunday.  I received an error message " Unable to process template language expressions in action 'Get_the_Day_of_the_Week_(Name)' inputs at line '0' and column '0': 'The template language expression 'variables('Days of the Week')[sub(outputs('Get_the_Day_of_the_Week_(Number)'),1)]' cannot be evaluated because array index '-1' is outside bounds (0, 6) of array. Please see https://aka.ms/logicexpressions for usage details.'. "  I have attached a word document with all of the code and error message that I'm receiving.  Any help would be appreciated.

Categories:
I have the same question (0)
  • Chriddle Profile Picture
    8,640 Super User 2026 Season 1 on at

    I assume that outputs('Get_the_Day_of_the_Week_(Number)' equals 0.

    Then you substract 1 and end up at -1 which is not a valid array index.

  • Michael E. Gernaey Profile Picture
    53,960 Moderator on at

    Hi,

     

    I would say you have an issue with the logic in your flow and would need to see the code inside the actions to help you, such as whatever the action Get_the_day_of_the_week_(Number) does because something is calculating a -1, which either means you think its all been working when in fact its a day off, or well too many ors.

     

    but please share the actual flow and logic


    Cheers
    If you like my answer, please Mark it as Resolved, and give it a thumbs up, so it can help others
    Thank You
    Michael Gernaey MCT | MCSE | Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • wskinnermctc Profile Picture
    6,519 Moderator on at

    Are you trying to get the day of the week number and then compare that to some array that you have made which contains the names of the week days?

     

    You can get the full name of the day of the week by using 'dddd' in formatDateTime()

    https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#ddddSpecifier 

     

    You wouldn't need to look up the name with something you created.

  • ZG11 Profile Picture
    8 on at

    Hi, I understand that is the issue, I'm unsure as to how to fix it.  See attached word document for my flow and the error message that it shows it being failed (its the picture with a red border).  Admittedly I'm very new to power automate but an odd thing is that it only is erroring out on Sunday, I reran it today with no issues and the email generated does say Monday.

  • ZG11 Profile Picture
    8 on at

    Unfortunately due to my company's IT limitations, I'm unable to directly share the workflow directly.  However, please see attached for the several screenshots of the workflow, including where I was receiving the error (it's highlighted in red).  Admittedly I'm very new to power automate but an odd thing is that it only is erroring out on Sunday, I reran it today with no issues and the email generated does say Monday so I don't think it's a scenario of being off a day.

  • ZG11 Profile Picture
    8 on at

    Admittedly I'm very new to power automate so I'm not sure I quite understand the solution proposed.  See attached word document, I was able to do screenshots of my workflow and show where the error was occurring.  Are you saying that I could remove 'initialize variable - weeks array' , 'Get UTC Date and Time now' , 'Get the Day of the Week (number)' , and 'Get the Day of the Week (Name)' and replace it with 'dddd' formula and it will show the day of the week name?

  • Michael E. Gernaey Profile Picture
    53,960 Moderator on at

    Hello,

     

    I am pretty stumped. I have replicated your entire flow. I also validated that it works with or without your date time conversion.

     

    Here is my recommendation. after the step where you get the day of the week number add a Compose and set it to the output of the step that gets the Number. 

     

    FLMike_0-1694481190228.png

     

    another thing we can try is to actually do a test, where you pick a date that is a monday, then keep changing it to the next day and the next day and see what the output is. Since I dont see any code issues, either its hidden and just not visible or your time stamps are doing something that mine aren't.
    Cheers
    If you like my answer, please Mark it as Resolved, and give it a thumbs up, so it can help others
    Thank You
    Michael Gernaey MCT | MCSE | Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

     

  • Chriddle Profile Picture
    8,640 Super User 2026 Season 1 on at

    It's pretty obvious:

    You get the day of week, if Sunday, this is 0.

    You substract 1 and end up with -1.

    This is not a valid array index.

     

    In PA the week starts with a Sunday and dayOfWeek() returns a number from 0 to 6.

    Why is your array of weekdays different from this? You should avoid this.

     

    You shouldn't simply substract from the return of dayOfWeek().

     

    To get the day's name, the format string 'dddd' does the trick, as @wskinnermctc already mentioned.

    If you need to know yesterday's day of week simply use

    addDays(utcNow(), -1, 'dddd')

    Returns Monday

    If you need today's day of week, it's

    utcNow('dddd')

    Returns Tuesday

     

    If you need this in a different language (maybe that's why you created the array), use formatDateTime() with a location string

    formatDateTime(utcNow(), 'dddd', 'es-es')

    Returns martes

     

    If it's somethig different, just tell us 😉

     

  • Chriddle Profile Picture
    8,640 Super User 2026 Season 1 on at

    If you really want to calculate with the returned number from dayOfWeek(), you usually have to ensure, that you stay within the bounds 0-6.

    A robust way to do so is with the function mod()

    Just add a number that is divisible by 7 and greater then the number you substract (you don't need that, if you only add numbers).

    E.g.

    mod(
    	add(
    		sub(
    			dayOfWeek(utcNow()),
    			6
    		),
    		7
    	),
    	700
    )

     

  • Verified answer
    wskinnermctc Profile Picture
    6,519 Moderator on at

    @ZG11 Here is an example of what you need to do. This is very simple and very similar to what you already have. If you use these steps, it should get the result you want.

     

    This uses the Convert Time Zone action, but in the drop down select Enter Custom Value and then type dddd into the Format String field.

    Here is a screenshot of entering a custom format string into Convert Time Zone:

    Convert Time Zone - Format String - Enter Custom Value - ddddConvert Time Zone - Format String - Enter Custom Value - dddd

     

    Here is an example of the entire flow that will get the current Day Name and put it into a string Variable that can be used elsewhere in a flow like an Email message:

    Example Flow - Set DayName to variableExample Flow - Set DayName to variableResults of Example FlowResults of Example Flow

     

    Try recreating my example and using it in your flow.

    If this solves your issue, please mark this response Accept as Solution.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 304

#2
David_MA Profile Picture

David_MA 245 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 243 Most Valuable Professional

Last 30 days Overall leaderboard