Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Connector Development
Suggested answer

power automate custom code connector not working properly

(1) ShareShare
ReportReport
Posted on by
Below code is not working. returned date is allways lessthan oneday. I am calling this code in powerautomate flow
 
DateTime AdjustDate(DateTime date)
{
if (date.DayOfWeek == DayOfWeek.Sunday)
return date.AddDays(1); // Move to Monday
else if (date.DayOfWeek == DayOfWeek.Saturday)
return date.AddDays(-1); // Move to Friday
else
return date; // No change
}
Categories:
  • Suggested answer
    Nived_Nambiar Profile Picture
    17,348 Super User 2025 Season 1 on at
    power automate custom code connector not working properly
     
    Code is working fine , I have checked it. But when using in Power Automate cloud flow - Date formats returned by data sources like sharepoint, excel etc would be in UTC format, also datetime returned by power automate expressions unless you are converting the UTC to your local timezone. So for example - you are using utcNow() to get current date and time , but it returns current date and time in UTC format which may be different from your timezone (may be some hours backwards which causes date to appear previous day) which would cause calculation wrong.
     
    So to resolve that - use convertFromUtc function which helps to convert the time from UTC to other timezone such as your local timezone- before you pass the datetime value to custom code connector.
     
     
    Hope it helps !
     

    Thanks & Regards,
    Nived N

    Stay connected:
    LinkedIn | YouTube | Blogs

    Was this answer helpful?
    If yes, please mark it as the solution by selecting the checkbox in the discussion thread.
    Your feedback motivates me to keep contributing. Thank you!

     

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

Thomas Rice – Community Spotlight

We are honored to recognize Thomas Rice as our March 2025 Community…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,508 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,440 Most Valuable Professional

Leaderboard

Featured topics