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 / Variable in expression...
Power Automate
Answered

Variable in expression- For date calculation throws error "invalid expression"

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

In my flow, I have a date calculation to subtract 8hours from current time like below.

addHours(utcNow(),-8,'yyyy-MM-ddThh:mm:ss')

 

I want to take this parameter value(8) from a variable. I have set an integer variable with value 8. so, new expression is like

addHours(utcNow(),-variables('varHours'),'yyyy-MM-ddThh:mm:ss').

 

But this expression is throwing error invalid expression.

 

please help?

Categories:
I have the same question (0)
  • v-yetonggu-msft Profile Picture
    Microsoft Employee on at

    Hi @prteotia ,

    I did a test for your reference.

    In my scenario:

    vyetonggumsft_1-1699945893755.png

    vyetonggumsft_3-1699945965116.png

     

    Best Regards,

    Sunshine Gu

     

     

  • Verified answer
    michael0808 Profile Picture
    304 on at

    This is where you're going wrong addHours(utcNow(),-variables('varHours'),'yyyy-MM-ddThh:mm:ss')

     

    Expressions don't work in this fasion. In order to get the negative of an integer, you can multiply by -1.

     

    Try this:

     

    addHours(utcNow(),mul(variables('varHours'), -1),'yyyy-MM-ddThh:mm:ss')

     

  • prteotia Profile Picture
    Microsoft Employee on at

    Thanks @michael0808 , it works.

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 573

#2
Valantis Profile Picture

Valantis 407

#3
11manish Profile Picture

11manish 387

Last 30 days Overall leaderboard