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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / power automate custom ...
Power Automate
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:
I have the same question (0)
  • Suggested answer
    Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at
     
    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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard