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 Apps / Expression for created...
Power Apps
Unanswered

Expression for created and modified time difference

(0) ShareShare
ReportReport
Posted on by 204

Hello, 

 

I have this expression on the "on select" property of an edit button (pencil icon) that shows a pop up and will not let others edit a report (data source- SharePoint) if it wasn't created by them. 

 

If('Submitted By_DataCard3'.Default= User().FullName, EditForm('Incident Report- Edit');Navigate('Edit Incident Report',ScreenTransition.Fade), Set(showpopup2, true))

 

Now I need to add another condition in here. They are no longer allowed to modify a report if it has been 12 hours since they created it.  How would I add that to this expression?

 

Thanks

 

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,991 Moderator on at

    @TorreyFalconer 

    You could use the DATEDIFF function to accomplish this task.  Change this section of your code:

    'Submitted By_DataCard3'.Default= User().FullName

     

    Into this code instead.

    'Submitted By_DataCard3'.Default= User().FullName && DateDiff(Created, Now(), Hours) <= 12

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

     

  • TorreyFalconer Profile Picture
    204 on at

    @mdevaney thanks, this does make sense to me...except for some reason it does not seem to be taking the 'created' property. Should that not always be available as it's part of the data source?

     

     

  • TorreyFalconer Profile Picture
    204 on at

    @mdevaney - 

     

    See picture: I also tried replacing Created with:

    'Created' 

    Created()

    'Created'.value

     

    and then I also tried a workaround to actually put the created date control in the form but set to invisible and even then it wouldn't seem to take the datacardvalue

    Annotation 2019-12-20 030155.jpg
  • mdevaney Profile Picture
    29,991 Moderator on at

    @TorreyFalconer 

    Can you please show me where you are typing that code (what object and what property)?  Having a screenshot of the error message would also help 🙂

     

    I've also changed by answer slightly from Created to ThisItem.Created assuming the code is in an Edit Form or Gallery

    'Submitted By_DataCard3'.Default= User().FullName && DateDiff(ThisItem.Created, Now(), Hours) <= 12
    

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • TorreyFalconer Profile Picture
    204 on at

    @mdevaney  whoops. For sure, that would be helpful information for you! See the screenshot below.

    I am in view mode, in the onSelect property 

    errorscreenshotpowerapps.jpg
  • mdevaney Profile Picture
    29,991 Moderator on at

    @TorreyFalconer 

    Perfect!  I know exactly what the issue is 🙂

     

    The error message means a screen or object has been deleted/renamed but is still being referred to in your code.  I think its one of these two screens.  Check if they still have a matching name on your left side menu.

     

    EditForm('Incident Report- Edit');Navigate('Edit Incident Report',ScreenTransition.Fade)

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • TorreyFalconer Profile Picture
    204 on at

    @mdevaney well that was a second issue that I totally didn't notice so thanks! But still not working, it does seem to be the 'Created' reference because when I hover over it, it says name isn't valid. But I've also tried it in so many variations (created, created(), thisitem.created, created.value, value.created, 'created', then tried adding a control in the app on invisible and tried: datacard14value. and created_datacard1.value etc etc)

    errorscreen2.jpg
  • mdevaney Profile Picture
    29,991 Moderator on at
    @TorreyFalconer
    Now I also know why Created is giving you problems. Your button is outside of the Edit Form (which is totally normal). However, you cannot reference the Created field while outside the form. It makes kinda makes sense because PowerApps is saying “where should I get the Created field from where exactly?

    You can get around this by storing the value of Created in a variable and referencing the variable instead. Did you browse to the Edit screen from a gallery? If yes, you can put this code in the OnVisible property of your Edit Screen.

    Set(varCreated, Gallery1.Selected.Created)

    Then in your DateDiff formula simply replace Created with varCreated.

    —-
    Please Accept as Solution if this post answered your question so others may find it more quickly. If you found this post helpful consider giving it a Thumbs Up.

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 Apps

#1
11manish Profile Picture

11manish 551

#2
WarrenBelz Profile Picture

WarrenBelz 430 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 298

Last 30 days Overall leaderboard