Skip to main content

Notifications

Power Automate - General Discussion
Answered

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

(0) ShareShare
ReportReport
Posted on by

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?

  • prteotia Profile Picture
    prteotia on at
    Re: Variable in expression- For date calculation throws error "invalid expression"

    Thanks @michael0808 , it works.

  • Verified answer
    michael0808 Profile Picture
    michael0808 304 on at
    Re: Variable in expression- For date calculation throws error "invalid expression"

    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')

     

  • Re: Variable in expression- For date calculation throws error "invalid expression"

    Hi @prteotia ,

    I did a test for your reference.

    In my scenario:

    vyetonggumsft_1-1699945893755.png

    vyetonggumsft_3-1699945965116.png

     

    Best Regards,

    Sunshine Gu

     

     

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard